How do i extract data from mysql using php in individ pages:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tovia2000
Forum Newbie
Posts: 12
Joined: Sat Aug 25, 2007 7:45 am

How do i extract data from mysql using php in individ pages:

Post by tovia2000 »

Hi

At the moment my pagination is produced in php:

Code: Select all

<?php
//create some variables
$pagenumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1;
//establish number of resulsts per page
$perpage = 10;
//establish a padding value
$padding = 7;
// get start index of results
$startindex = ($pagenumber * $perpage) - $perpage;

// header top menu and menu---------------------------------------------------------------- 
include("includes/head.html");


print "<div id = menuwrap>";
include("includes/menu.html");
// include("banner_left.html");
print "</div>";

include("db/db_config.php");
// get total number of dbms entries
$totalcount = "SELECT COUNT(*) as 'Total' FROM test.articles";
$rscount = mysql_query($totalcount) or die(mysql_error());
$rowcount = mysql_fetch_object($rscount);

// get page results
$sql = "SELECT timestamp1,title,author,body FROM test.articles_view ORDER BY timestamp1 desc
LIMIT $startindex, $perpage";
// get result set
$rs = mysql_query($sql) or die(mysql_error());

print "<div id =\"container\">";

print "<div id =\"article\">";
print "Articles";
print "</div>";


// do we have results
if (mysql_num_rows($rs) > 0) {
// show the results
while ($row = mysql_fetch_object($rs)) {
print "<LINK REL=STYLESHEET HREF=\"styles/pagination.css\" TYPE=\"text/css\">";


print "<div id = title>";
print "<b>  " . $row->title . "  </b>";
print "</div>";

print "<div id = author>";
print "<b>  " . $row->author . "  </b>";
print "<b>  " . $row->timestamp1 . "  </b>";
print "</div>";

print "<div id = body>";
print $row->body;
print "... ";
print "</div>";	
print "<p>";

}

} 

else {
    print "Sorry, no articles found.";
}

// Show page listings -----------------------------------------------------
print "<div align=\"center\">";
// pages division
print "<div id = pages>";
// get our total number of pages
$numofpages = ceil($rowcount->Total / $perpage);
	// print link to first page
	print "<a href=\"articles.php?page=1\">First</a> ";
//Show page listings to left:---------------------------------------------------
// if our current page, minus our padding is greater than 1
   if (($pagenumber - $padding) > 1) {
        print "... ";
        // set our lower limit
	$lowerlimit = $pagenumber - $padding;
	// print all padded numbers between lowerlimit and current page
	for($i = $lowerlimit; $i < $pagenumber; $i++) {
		print "<a href=\"articles.php?page=".$i."\">".$i."</a> ";
	}
} else {
   // print all numbers between current page, and first page
   for($i = 2; $i < $pagenumber; $i++) {
	print "<a href=\"articles.php?page=".$i."\">".$i."</a> ";
	}
}
//End page listings to left:---------------------------------------------------
// if were not on the first page, or the last page, print current page
if(($pagenumber !=0) && ($pagenumber !=1) && ($pagenumber != $numofpages))
{ print "<b> - " . $pagenumber . " - </b>"; }
//Show page listings to right:---------------------------------------------------
// if our current page, plus our padding , is less than the total number of pages
if (($pagenumber + $padding) < $numofpages) {
// set upper limit
$upperlimit = $pagenumber + $padding;
// print all numbers from padded pages above current page
for($i = ($pagenumber + 1); $i <= $upperlimit; $i++) {
		print "<a href=\"articles.php?page=".$i."\">".$i."</a> ";
		}
		print "... ";
	} else {
//print all page numbers between number of pages and current page
	for($i = ($pagenumber +1); $i < $numofpages; $i++) {
		print "<a href=\"articles.php?page=".$i."\">".$i."</a> ";
	}
}
// print link to last page
print "<a href=\"articles.php?page=".$numofpages."\">Last</a>";
//End page listings to right:---------------------------------------------------
print "</div>";
print "</div>";
print "<p>";
print "</div>";	


// footer file includes left hand side banners tiny url, banner------------------------------
print "<div align=\"center\">";
include("includes/footer.html");
print "</div>";

print "<div id = bodyad>";
include("includes/bodyad.html");
print "</div>";

//close our dbms connection
mysql_close($link);

?>

which produces pagination like:
http://www.articlesbase.com/art-and-ent ... -articles/

Note:
Above data is based on a view so i display partial body column, like they have done so for pagination, my view:

Code: Select all

mysql_query ("CREATE view articles_view AS select id,timestamp1,Title,author,author_box,substr(body,1,350) from articles")
or die(mysql_error());
echo "View articles_view Created!";
1.Problem:
How do i make:

Code: Select all

print "<b> " . $row->title . " </b>";
a href link link like they have above in there site:
http://www.articlesbase.com/art-and-ent ... -articles/

for the title, so when clicked it opens the whole data, full body column from the table in a separate page including title like:
http://www.articlesbase.com/art-and-ent ... 55962.html

Each record in the database represents an individual page.


2.Problem:
Does data in mysql database get indexed by search engines google, yahoo etc? or do i need to spool out data into seperete html files?

I am a PHP newbie, they must be an example of this code somewhere , i am really stuck, , although i have done the hard part which was pagination i suppose, i cant believe how difficult this part is proving.

Surely putting each record into seperate pages and each page being accessible via clicking on the title column in the pagintion cant be difficult, must be an exmaple somewhere.

Have google dit for 3 weeks or so, found lots on pagination etc, nothing on this.

Thanks in advance

Tovia Singer
Post Reply