Sponsored Links
No booking fees on all published flights!


Post Reply 
 
Thread Rating:
  • 1 Votes - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MYSQL/PHP Code To View Tables
06-06-2009, 09:00 AM
Post: #1
MYSQL/PHP Code To View Tables
Here is another example to display all rows in a table. Replace the connection and table variables with your own.

viewall.php
PHP Code:
<html>
<head><title>Your Page Title</title></head>
<body>
<?php
$database="yourdbname";
mysql_connect ("localhost", "yourusername", "yourpassword");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT * FROM yourtable" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=400 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
</body>
</html>


Here is some more code to select only rows from a table.

viewcertainfields.php
PHP Code:
<html>
<head><title>Your Page Title</title></head>
<body>
<?php
$database="yourdbname";
mysql_connect ("localhost", "yourusername", "yourpassword");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT field1, field2, field3 FROM yourtable" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
?>
</body>
</html>
You can also add limit and order to the query.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)