+ Reply to Thread
Page 1 of 4
1 2 3 ... LastLast
Results 1 to 10 of 38

Thread: Displaying records from a mySQL DB

  1. #1
    Newbie aakinn is an unknown quantity at this point
    Join Date
    Mar 2010
    Posts
    20

    Question Displaying records from a mySQL DB

    Hello all

    I am currently trying to teach myself some PHP and mySQL work in order to build a DB driven website.

    I have a table in my database which stores information about a product eg (product name, price, description, image(set as a blob))

    What I want to do is list all the items in this table in a webpage with the image showing following by the name and price of the item under it, something similar to the way Game.co.uk website displays their product information

    I also would like when an item has been clicked on to show a new page with all the item's details.

    Are there ay templates any knows of or has which I could go by as I am struggling to get this working

    Kind Regards

    Akin

  2. #2
    Code Warrior BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    20
    Posts
    2,247
    Blog Entries
    8

    Re: Displaying records from a mySQL DB

    You'd need 3 pages. The products page which displays all products, the image which will display the image, and the product details page which will show all the details about the product.

    Code:
    <?PHP
    //display all products
    $query mysql_query("SELECT * FROM `products`") or die(mysql_error());
    while(
    $row=mysql_fetch_assoc($query)) {
        
    //format the output
        
    echo '<a href="fullProduct.php?id='.$row['id'].'"><img  src="image.php?id='.$row['id'].'">'.$row['name'].'</a>';
    }
    Code:
    <?PHP
    //display image
    $id $_GET['id'];//FILTER!!
    $query mysql_query("SELECT `image` FROM `products` WHERE `id`='$id'") or die(mysql_error());
    while(
    $row=mysql_fetch_assoc($query)) {
        
    $im imagecreatefromstring($row['image']);
        if (
    $im !== false) {
            
    header('Content-Type: image/png');
            
    imagepng($im);
            
    imagedestroy($im);
        }
        else {
            echo 
    'An error occurred.';
        }
    }
    Code:
    <?PHP
    //display full product
     
    $id $_GET['id'];//FILTER!!
     
    $query mysql_query("SELECT * FROM `products` WHERE `id`='$id'")  or die(mysql_error());
     while(
    $row=mysql_fetch_assoc($query)) {
         
    //format the output
     
    }

  3. #3
    Newbie aakinn is an unknown quantity at this point
    Join Date
    Mar 2010
    Posts
    20

    Re: Displaying records from a mySQL DB

    Excellent thats worked like a charm thanks alot mate just another quick thing

    When im formatting the output I want each image to appear side by side/horizontally with the details of the items below the image so far I have this

    ...//display all products
    $query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
    while($row=mysql_fetch_assoc($query)) {
    //format the output
    echo '<table border="1" cellpadding="10">
    <tr>
    <td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"> </td>
    </tr>
    <td>'.$row['name'].'</a><br />£'.$row['price'].'</td>
    </tr>
    </table>';
    }

    This displays the details below the images as I want but each record is shown vertically, how would I get the images to appear side by side?

    Thanks

  4. #4
    Code Warrior BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    20
    Posts
    2,247
    Blog Entries
    8

    Re: Displaying records from a mySQL DB

    Try this
    Code:
    <?PHP //display all products
    $query mysql_query("SELECT * FROM tblItems") or die(mysql_error());
    while(
    $row=mysql_fetch_assoc($query)) {
        
    //format the output
        
    echo '<table border="1" cellpadding="10">
        <tr>
        <td><a href="fullProduct.php?id='
    .$row['id'].'"><img  src="image.php?id='.$row['id'].'"></a></td>
        <td><a  href="fullProduct.php?id='
    .$row['id'].'">'.$row['name'].'</a><br  />£'.$row['price'].'</td>
        </tr>
        </table>'
    ;
    }

  5. #5
    Newbie aakinn is an unknown quantity at this point
    Join Date
    Mar 2010
    Posts
    20

    Re: Displaying records from a mySQL DB

    I have tryed that already, that displays the image in one column with the details in a column next to it

    I have been toying with it for some time now and cannot get it to display the images in one row and the details in a row below

  6. #6
    Code Warrior BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    20
    Posts
    2,247
    Blog Entries
    8

    Re: Displaying records from a mySQL DB

    Oh, sorry. I misunderstood.
    Code:
     <?PHP //display all products
    $query mysql_query("SELECT * FROM tblItems") or die(mysql_error());
    while(
    $row=mysql_fetch_assoc($query)) {
        
    //format the output
        
    echo '<table border="1" cellpadding="10">
        <tr>
            <td><a href="fullProduct.php?id='
    .$row['id'].'"><img  src="image.php?id='.$row['id'].'"></a></td>
        </tr>
        <tr>
            <td><a  href="fullProduct.php?id='
    .$row['id'].'">'.$row['name'].'</a><br  />£'.$row['price'].'</td>
        </tr>
        </table>'
    ;
    }
    I think you just forgot to close the tr tag.

  7. #7
    Newbie aakinn is an unknown quantity at this point
    Join Date
    Mar 2010
    Posts
    20

    Re: Displaying records from a mySQL DB

    That is still producing the images below one another and not side by side

    The code was exactly the same as I had and it does seem to make sence but displays as soo

    [IMAGE]
    [Image details]
    [IMAGE]
    [Image details]
    [IMAGE]
    [Image details]

    Where it should be


    [IMAGE] [IMAGE] [IMAGE]
    [Image details] [Image details] [Image details]


  8. #8
    Code Warrior BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch is a name known to all BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    20
    Posts
    2,247
    Blog Entries
    8

    Re: Displaying records from a mySQL DB

    Code:
     <?PHP //display all products
    $query mysql_query("SELECT * FROM tblItems") or die(mysql_error());
    echo 
    '<table border="1" cellpadding="10"><tr>';
    while(
    $row=mysql_fetch_assoc($query)) {
        
    //format the output
        
    echo '<td><a href="fullProduct.php?id='.$row['id'].'"><img  src="image.php?id='.$row['id'].'"></a><br />'.
            
    '<a  href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br  />£'.$row['price'].'</td>';
    }
    echo 
    '</tr></table>';
    }

  9. #9
    Newbie aakinn is an unknown quantity at this point
    Join Date
    Mar 2010
    Posts
    20

    Re: Displaying records from a mySQL DB

    Thats the one

    There was an extra } in there but took it out and worked!

    Thanks alot it is very much appreciated!!


  10. #10
    Newbie aakinn is an unknown quantity at this point
    Join Date
    Mar 2010
    Posts
    20

    Re: Displaying records from a mySQL DB

    How would I be able to specify a new row to start? as currently the data outputs in one continious row.

    I have put the table in a div tag and the width has been set to 600px yet the table continues past the tags specified width and carrys on showing in one continous line

+ Reply to Thread
Page 1 of 4
1 2 3 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. How can I delete mySQL records from an html or jsp page?
    By bigz008 in forum Database & Database Programming
    Replies: 2
    Last Post: 03-05-2010, 09:37 AM
  2. Activation Records
    By atrip25 in forum General Programming
    Replies: 3
    Last Post: 11-07-2009, 06:33 AM
  3. Records and TStringLists?
    By SirStorm25 in forum Pascal/Delphi
    Replies: 1
    Last Post: 12-03-2008, 08:21 AM
  4. displaying mysql data into jtextfield.Pls help
    By iz.ziffa in forum Java Help
    Replies: 1
    Last Post: 05-31-2007, 07:58 AM
  5. Selecting records with a condition
    By ashleysmithd in forum Database & Database Programming
    Replies: 7
    Last Post: 05-05-2007, 10:54 AM