SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying a record from my database table order

    How can i display one record from my database table 'order' this is what i have so far:

    PHP Code:
    <html>
    <head>
    <title>view order</title>
    </head>
    <html>

     <body><body bgcolor="#6699FF">
    <p><font face="Berlin Sans FB" size="5" color="#000080">View order</font></p>
    <p><font color="#000080" size="4" face="Berlin Sans FB">This is your order to confirm and place the order click on the confirmation button 
    at the bottom of the page</font></p>
    </body>
    </html>
        <html>
        <body><font face="Berlin Sans FB" size="3" color="#000080"><b>

    <table>
        <table width="72%" border="2" p align="center" height="45">
    <tr><p align="center">
    <td width="92"><p align="center"><font face="Berlin Sans FB" color="#000080"><B>order id</B></font></td>
    <td width="111"><p align="center"><B><font face="Berlin Sans FB" color="#000080">Customer id</font></B></td>
    <td width="220"><p align="center"><font face="Berlin Sans FB" color="#000080"><I><B>Date</B></I></font></td>
    <td width="260"><p align="center"><b><font face="Berlin Sans FB" color="#000080">time</font></b></td>
    <td width="300"><p align="center"><b><font face="Berlin Sans FB" color="#000080">menuid</font></b></td>
    <td width="340"><p align="center"><b><font face="Berlin Sans FB" color="#000080">qty</font></b></td>
    <td width="380"><p align="center"><b><font face="Berlin Sans FB" color="#000080">total bill</font></b></td>
    </tr>

    <?
    $username
    ="root";
    $password="mehul";
    $database="delivery";

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");

    $query="SELECT * FROM orderdetails";
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    mysql_close();

    $i=0;
    while (
    $i $num) {
    $orderid=mysql_result($result,$i,"orderid");
    $customerid=mysql_result($result,$i,"customer id");
    $date=mysql_result($result,$i,"date");
    $time=mysql_result($result,$i,"time");
    $menuid=mysql_result($result,$i,"menuid");
    $qty=mysql_result($result,$i,"qty");
    $totalbill=mysql_result($result,$i,"totalbill");

    ?>

    <body bgcolor="#6699FF">
    <table>
    <table width="72%" border="2" p align="center" height="45">
    <tr><p align="center">
    <td width="92"><p align="center"><font face="Berlin Sans FB" color="#000080"><B><? echo $orderid?></B></font></td>
    <td width="111"><p align="center"><font face="Berlin Sans FB" color="#000080"><B><? echo $customerid?></font></B></td>
    <td width="220"><p align="center"><font face="Berlin Sans FB" color="#000080"><I><B><? echo $date?></B></I></font></td>
    <td width="260"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $time?></font></td>
    <td width="300"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $menuid?></font></td>
    <td width="340"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $qty?></font></td>
    <td width="380"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $totalbill?></font></td>
    </tr>

    </table>

    <?
    $i
    ++;
    }

    echo 
    "</table>";
    </
    font>&nbsp;<a href="confirmation.html"><img border="0" src="vieworder.gif" width="95" height="20">
    i would like to display an record from my table that has an order id of 1
    in a tabular format

    please some1 help

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
     $query="SELECT * FROM orderdetails WHERE orderid = 1"
     
    $result=mysql_query($query); 
      
     
    $row mysql_fetch_array($result);
      
     
    $orderid=$row["orderid"];
     
    $customerid=$row["customer id"]; 
     
    $date=$row["date"]; 
     
    $time=$row["time"]; 
     
    $menuid=$row["menuid"]; 
     
    $qty=$row["qty"]; 
     
    $totalbill=$row["totalbill"]; 
    Try this.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THanks for the help.

    i change my code to this:
    Code:
    <html><body><p><b><font face="Berlin Sans FB" size="5" color="#000080">ALL ORDERS MADE:</b></p></font>
    <p><b><font face="Berlin Sans FB" size="3" color="#000080"><p align  = right><a href=personaldetails.php>click here to see your personal details</b></p></font></a href>
    
    <table>
    <tr><table width="72%" border="2" p align="center" height="45">
    <tr><p align="center">
    <td width="92"><p align="center"><font face="Berlin Sans FB" color="#000080"><B>order id</B></font></td>
    <td width="111"><p align="center"><B><font face="Berlin Sans FB" color="#000080">Customer id</font></B></td>
    <td width="220"><p align="center"><font face="Berlin Sans FB" color="#000080"><I><B>Date</B></I></font></td>
    <td width="260"><p align="center"><b><font face="Berlin Sans FB" color="#000080">time</font></b></td>
    <td width="300"><p align="center"><b><font face="Berlin Sans FB" color="#000080">menuid</font></b></td>
    <td width="340"><p align="center"><b><font face="Berlin Sans FB" color="#000080">qty</font></b></td>
    <td width="380"><p align="center"><b><font face="Berlin Sans FB" color="#000080">total bill</font></b></td>
    </tr>
    
    <?
    $username="root";
    $password="mehul";
    $database="delivery";
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $query="SELECT * FROM orderdetails WHERE orderid = 1";
    $result=mysql_query($query);
      
    $row = mysql_fetch_array($result);
      
    $orderid=$row["orderid"];
    $customerid=$row["customer id"];
    $date=$row["date"];
    $time=$row["time"];
    $menuid=$row["menuid"];
    $qty=$row["qty"];
    $totalbill=$row["totalbill"]; 
    ?>
    
    <body bgcolor="#6699FF">
    <table>
    <tr><table width="72%" border="2" p align="center" height="45">
    <tr><p align="center">
    <td width="92"><p align="center"><font face="Berlin Sans FB" color="#000080"><B><? echo $orderid; ?></B></font></td>
    <td width="111"><p align="center"><font face="Berlin Sans FB" color="#000080"><B><? echo $customerid; ?></font></B></td>
    <td width="220"><p align="center"><font face="Berlin Sans FB" color="#000080"><I><B><? echo $date; ?></B></I></font></td>
    <td width="260"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $time; ?></font></td>
    <td width="300"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $menuid; ?></font></td>
    <td width="340"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $qty; ?></font></td>
    <td width="380"><p align="center"><font face="Berlin Sans FB" color="#000080"><? echo $totalbill; ?></font></td>
    </tr>
    
    </table>
    
    <?
    
    }
    
    echo "</table>";
    than when clicking a button to this page.. nothing appears.
    please help
    thanks

  4. #4
    SitePoint Enthusiast BurakUeda's Avatar
    Join Date
    Apr 2005
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check if you have some error in your SQL string:
    PHP Code:
    $result=mysql_query($query) or die ("Cannot run query: ".mysql_error()); 
    or check if you have any results
    PHP Code:
     $result=mysql_query($query) or die ("Cannot run query: ".mysql_error());
    echo 
    mysql_num_rows(); 
    H u m o
    Uncensored Forums for Intelligent People

  5. #5
    SitePoint Member ruddhim's Avatar
    Join Date
    Mar 2005
    Location
    India
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Supremefiend is your field order_id an integer field or a character field or varchar.
    If it is a character field (lets say size 4) then u will have to specify the query as
    PHP Code:
     $query="SELECT * FROM orderdetails WHERE orderid = '0001' "
    Or if it is only varchar use single quotes as in
    PHP Code:
     $query="SELECT * FROM orderdetails WHERE orderid = '1' "

  6. #6
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the table. it is an interger
    customer CREATE TABLE `customer` (
    `Customerid` int(11) NOT NULL auto_increment,
    `Firstname` varchar(25) default NULL,
    `Lastname` varchar(25) default NULL,
    `Addressline1` varchar(25) default NULL,
    `Addressline2` varchar(25) default NULL,
    `Town` varchar(25) default NULL,
    `Postcode` varchar(7) default NULL,
    `Telephoneno` int(10) unsigned default NULL,
    `username` varchar(25) NOT NULL default '',
    `Email` varchar(25) NOT NULL default '',
    PRIMARY KEY (`Customerid`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1


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
  •