Advanced Search

Results 1 to 7 of 7

Thread: how to show entries from mysql database

  1. #1
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to show entries from mysql database

    Hey.
    I have a table with different information.
    (item id, name, price)

    How do i make a php document to output all the entries in the table on one document. (a list with the items)

    eg.:
    (item 1, coca cola, 1,00$
    item 2, fanta, 1,00)

    Im not shure what the sql and php code is?
    please help

  2. #2
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If you want just to print the records on each row ...you coud make something like this

    if the table looks like this:
    item fieldName price
    item1 coca cola 1,00$

    $query = "select * from tableName";
    $request = mysql_query($query);
    while($row = mysql_fetch_array($request))
    {
    print $row["item"].' '.$row["fieldName"].' $'.$row["price"]."\n";
    }

    This will print the record from the table row by row.

  3. #3
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ill try that.. thank you so far

  4. #4
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hmm it does come up, but very messy. im pretty new to the php, so im clueless. is it possible to make it alle arranged into a table, so it prints nicely on the site?

  5. #5
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    $query = "select * from tableName";
    $request = mysql_query($query);
    echo('<table border=1>');
    while($row = mysql_fetch_array($request))
    {
    echo '<tr><td>' . $row["item"] . '</td>';
    echo '<td>' . $row["fieldName"] . '</td>';
    echo '<td>' . $row["price"] . '</td></tr>';
    }
    echo ('</table>');
    i think
    Last edited by jr_yeo; 07-26-2006 at 09:18 PM. Reason: typo
    Please don't mind me. I am just posting a lot of nonsense.

  6. #6
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    That was close
    Code:
    $query = "select * from tableName";
    $request = mysql_query($query);
    echo('<table border=1>');
    while($row = mysql_fetch_array($request))
    {
    echo '<tr>';
    echo '<td>' . $row["item"] . '</td>';
    echo '<td>' . $row["fieldName"] . '</td>';
    echo '<td>' . $row["price"] . '</td>';
    echo '</tr>';
    }
    echo ('</table>');

  7. #7
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks guys

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
  •