#native_company# #native_desc#
#native_cta#

Display mysql restult as table

By Tom Smith — html, php, mysql, linux
on May 7, 2002

Version: 1.0

Type: Full Script

Category: HTML

License: GNU General Public License

Description: Problem: Take a row from a table of images and display thumbnails x number across.
Just change the value of $tds to change how many it shows across the row.

# make db connection 
$db = mysql_connect(localhost, user, pass);
mysql_select_db("database", $db);

# select whatever you want after the id and img fields
$sql = "select id, img from art ";
$res = mysql_query($sql, $db);

# count total rows
$tot = mysql_num_rows($res);

# change this to change how many tds are displayed before row ends
$tds = 4;

echo "<table border=1 width=100%>";
echo "<tr>";
for ($i = 1; $i <= $tot; $i++) {
	$row = mysql_fetch_row($res);
	$id = $row[0];
	$img = "<td align=center><a href=source/index.php?id=$id><img src=preview/$row[1]><br> $i / $tot</a></td>n";
	echo "$img";
	if ($i % $tds == '0' && $i < $tot) {
		echo "</tr>n<tr>n";
	} 
}
echo "</tr></table>";