#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Sacramento
    Posts
    50
    Rep Power
    15
    Hi,

    I would appreciate it if someone could help with this problem.

    I have a piece of code that grabs data from a database and displays in a table and for each record it creates a new row in the table: ie:

    echo "<tr>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$CREATED</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$ID</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$F_CUSTOMER_ID, $customer_name</font></td>

    </tr>";

    The php code I have works fine, no problems. The problem I have is I want to take those ids and display their names as well as the ids and I get all kinds of php errors.

    I am using this code:


    // create SQL statement

    $sql = "SELECT NAME

    FROM CUSTOMER

    WHERE ID= '$F_CUSTOMER_ID'";

    // execute SQL query and get result
    $sql_result = mysql_query($sql,$connection)
    or die("Couldn't execute query.");

    // put data into drop-down list box
    while ($row = mysql_fetch_array($sql_result)) {

    $customer_name = $row["NAME"];

    The bottom line:

    Would like to grab data from a table, data which consists of id numbers and convert those id numbers to their matching names and most importantly, create a table row for each record.

    Sorry for the long post, any help would be greatly appreciated.

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by tbalanco:
    echo "<tr>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$row[CREATED]</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$row[ID]</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$row[F_CUSTOMER_ID], $row[customer_name]</font></td>

    </tr>";
    [/quote]

    I would wrap this in your WHILE loop and change your sql to this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
    $sql = "SELECT * FROM CUSTOMER

    WHERE ID= '$F_CUSTOMER_ID'";
    [/quote]


    ------------------
    http://back-end.org
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Sacramento
    Posts
    50
    Rep Power
    15
    Forgive me for the long post. I figured I would show you the whole file as it is now. This part works fine. What I need is to add some code to this file that converts the ID #s into their matching name in the db. Maybe this will help. Thanks!

    The file:

    <?

    /create connection

    $connection = mysql_connect (localhost, ####, ###) or die ("Couldn't connect to server.");


    // select database


    $db = mysql_select_db (DB, $connection) or die ("Couldn't select database.");


    // create SQL statement


    $sql = "SELECT ID, CREATED, F_LOCATION_ID, F_CUSTOMER_ID, F_FUEL_TYPE_ID, F_DELIVERY_ID, VOLUME, PRICE
    FROM BID
    WHERE REVIEWED = 0";

    // execute SQL query and get result

    $sql_result = mysql_query($sql,$connection) or die ("Couldn't execute query.");


    //start results formatting

    echo "<br><br><div align=center>";

    echo "<table border=0 cellpadding=3 cellspacing=3 width='90%'>";

    echo "<tr><td colspan=9><font face='verdana,arial,helvetica' size='+1' color='#000000'><b>New Bids</b></font></td></tr>";


    // format results by row


    while ($row = mysql_fetch_array($sql_result)) {


    $CREATED = $row["CREATED"];
    $ID = $row["ID"];
    $F_CUSTOMER_ID = $row["F_CUSTOMER_ID"];
    $F_LOCATION_ID = $row["F_LOCATION_ID"];
    $F_FUEL_TYPE_ID = $row["F_FUEL_TYPE_ID"];
    $F_DELIVERY_ID = $row["F_DELIVERY_ID"];
    $VOLUME= $row["VOLUME"];
    $PRICE = $row["PRICE"];
    $REVIEWED = $row["REVIEWED"];
    $ACCEPTED = $row["ACCEPTED"];
    $COMMENTS = $row["COMMENTS"];

    echo "<tr bgcolor='#999999'>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Date:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b> Bid Number:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Customer:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Location:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Fuel Type:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Delivery Type:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Volume:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Price:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Accept:</b></font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'><b>Decline:</b></font></td>

    </tr>";


    echo "<tr>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$CREATED</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$ID</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$F_CUSTOMER_ID, $customer_name</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$F_LOCATION_ID</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$F_FUEL_TYPE_ID</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$F_DELIVERY_ID, $delivery_name</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$VOLUME</font></td>

    <td><font face='verdana,arial,helvetica' size='-2' color='#000000'>$PRICE</font></td>


    <td>

    <form action= method=GET>
    <input type=hidden name='ID' size=25 maxlength=25>
    <input type=submit value=Accept>
    </form>

    </td>

    <td>

    <form action= method=GET>
    <input type=hidden name='ID' size=25 maxlength=25>
    <input type=submit value=Reject>
    </form>

    </td>

    </tr>";

    }


    echo "</table>";


    echo "</div>";

    include("footer.inc");


    //free resources and close connection


    mysql_free_result($sql_result);
    mysql_close($connection);


    ?>

Similar Threads

  1. Replies: 3
    Last Post: February 11th, 2004, 09:30 AM
  2. Will table size affect data retrival time?
    By abones in forum Oracle Development
    Replies: 1
    Last Post: February 10th, 2004, 09:55 AM
  3. Replies: 0
    Last Post: January 30th, 2004, 03:18 PM
  4. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  5. How to Extract data from html table?
    By zlozi in forum PHP Development
    Replies: 4
    Last Post: January 17th, 2004, 08:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo