...

View Full Version : PHP display total # of something code



jmoney3457
12-12-2008, 12:25 AM
so i have a display script that displays all the vehicles in the database but now I want to display how many vehicles are in the database how would i do this? heres my code:


<?
include 'connect.inc.php';
session_start();
if (($_SESSION[auth]='yes') and ($_SESSION[level]==1) or ($_SESSION[level]==2) or ($_SESSION[level]==3)) {
$sort=$_GET[sort];
if (!$sort){
$sort="make";
$sort="price";
}
$query="SELECT * FROM vehicles order by $sort";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

echo "<b><center>Database Output</center></b><br><br>
<br><br><table width=50% border=1>
<tr><th>VID</th><th>year</th><th><a href=display.php?sort=make>make</a></th><th>model</th><th><a href=display.php?sort=price>price</a></th><th>image</th></tr>";

$i=0;
while ($i < $num) {
$vid=mysql_result($result,$i,"vid");
$year=mysql_result($result,$i,"year");
$make=mysql_result($result,$i,"make");
$model=mysql_result($result,$i,"model");
$price=mysql_result($result,$i,"price");
$image=mysql_result($result,$i,"image");

echo "the current date is:";
echo date("m/d/y");
echo "<tr><td>$vid</td><td>$year</td><td>$make</td><td>$model</td><td>$price</td><td>$image</td><td><a href=purchase.php?vid=$vid>purchase</a></td></tr>";
$i++;
}
}
else { header('Location:index.php');
}
?>

masterofollies
12-12-2008, 03:02 AM
mysql_num_rows()

http://us.php.net/mysql_num_rows

jmoney3457
12-12-2008, 03:58 AM
it worked thx:]

masterofollies
12-12-2008, 04:25 PM
No prob



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum