Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2007
    Location
    Maine
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question PHP display total # of something code

    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:
    PHP 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');
    }
     
    ?>
    Last edited by jmoney3457; 12-12-2008 at 04:16 AM.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

  • #3
    New Coder
    Join Date
    Nov 2007
    Location
    Maine
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    it worked thx:]
    Last edited by jmoney3457; 12-12-2008 at 04:33 AM.

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    No prob


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •