So, you've connected to the database, created your table, and inserted some data into that table. Now what do you do with it? Well, you read the data from the table and display on your website, using the following code:
$rows = 20; // the number of table rows to display
// read data from database
$result = mysql_query("select * from $table order by id desc limit $rows", $link)
or die ("Could not read data because ".mysql_error());
// print the data in a table
if (mysql_num_rows($result)) {
print "<table cellpadding=2 cellspacing=0 border=0 width=\"100%\">\n";
while ($qry = mysql_fetch_array($result)) {
print "<tr><td><a href=\"" . "$qry[email]\" target=\"_blank\">$qry[name]</a>: ";
print $qry[comment];
print "</td></tr>\n";
}
print "</table>\n";
}
With mysql_query we select all the entries in the table and order them by their $id number. We also limit the displayed entries to the number defined in the $rows variables, so in this case, only 20 entries will be displayed.mysql_close();And that is all the code you'll need for a simple MySQL guestbook script! If you have trouble putting it together, take a look at all the code.
Can't find what you're looking for? Try searching for it:
© 2000-2008 Xentrik.Net