SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling Multiple Database Entries

    I am putting the finsihing touches on my final project for class and it is an ecom site that also allows you to log in and view previous orders. Well it only pulls 1 entry from the database even if there are 3 entries, I am not sure what is wrong with my code as to why it won't pull all the entries. Here is the code:

    PHP Code:
    <?php
    //assumes that opendbo called, and session started when call is made.
    function displayorders() {
     global 
    $order$order_id$p_id$username$quantity$cart$DBname$link$totalprice;
     print (
    "Username:");
    print (
    "&nbsp;&nbsp;");
    print 
    $_SESSION['username'];
     print (
    "<br><br>");
    print (
    "<table>");
     print (
    "<tr><td> Product ID </td> <td> Product Name </td><td> Quantity </td></tr>");

    $query="SELECT * FROM ordereditems WHERE username='{$_SESSION['username']}'";
    $result mysql_query($query); 

    if (
    SqlNumRows($result) > 0) { 
       
    $result mysql_db_query($DBname$query$link) or die($sql); 
       
    $p_id mysql_result($result,0,"p_id");
       
    $p_name mysql_result($result,0,"p_name");
       
    $quantitymysql_result($result,0,"quantity");

       print (
    "<tr><td> $p_id </td> <td> $p_name </td><td> $quantity </td>         </td> ");
       print (
    "<tr><td> &nbsp </td> <td> &nbsp </td><td> &nbsp </td>         </td> ");
      }
     print(
    "<tr> <td> TOTALS </td> <td> </td> <td> $quantity items</td><td> $totalpricef </td></tr>  </table>");
    }

    ?>

  2. #2
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, take a look here.
    The function is depreceated. So...

    PHP Code:
    <?php
    //assumes that opendbo called, and session started when call is made.
    function displayorders() {
    global 
    $order$order_id$p_id$username$quantity$cart$DBname$link$totalprice;
    print (
    "Username:");
    print (
    "&nbsp;&nbsp;");
    print 
    $_SESSION['username'];
    print (
    "<br><br>");
    print (
    "<table>");
    print (
    "<tr><td> Product ID </td> <td> Product Name </td><td> Quantity </td></tr>");

    $query="SELECT * FROM ordereditems WHERE username='{$_SESSION['username']}'";
    $result mysql_query($query);

    if (
    SqlNumRows($result) > 0) {
    /*
       $result = mysql_db_query($DBname, $query, $link) or die($sql);
       $p_id = mysql_result($result,0,"p_id");
       $p_name = mysql_result($result,0,"p_name");
       $quantity= mysql_result($result,0,"quantity");
    */
        
    while($row mysql_fetch_assoc($result)) {
            
    $p_id $row['p_id'];
            
    $p_name $row['p_name'];
            
    $quantity $row['quantity'];
            print (
    "<tr><td> $p_id </td> <td> $p_name </td><td> $quantity </td>         </td> ");
            }
    print (
    "<tr><td> &nbsp </td> <td> &nbsp </td><td> &nbsp </td>         </td> ");
      }
    //Not sure what you are trying to achieve on the line below...
    //Do you mean a total quantity of all items?
    print("<tr> <td> TOTALS </td> <td> </td> <td> $quantity items</td><td> $totalpricef </td></tr>  </table>");
    }

    ?>
    I hope that does what you wanted.

  3. #3
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works perfectly You saved this students life Thank you

  4. #4
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are most welcome


Bookmarks

Posting Permissions

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