Retrieve data insert database!!

Discussion in 'PHP' started by ipohismytown, Feb 23, 2010.

  1. #1
    i want to retrieve the information from database to display a product pictures.

    Database Information
    
    Table name : product
    Column name : prod_img_url 
    Information inside the column : pic1.jpg,pic2.jpg,pic3.jpg
    
    PHP:
    Image display ( i only want display 1 result for "pic1.jpg")
    <img src="/localhost/images/<?php echo $row['prod_img_url']"?>
    PHP:

    How to code for only take the first picture address (pic1.jpg) and ignored other?Please help Urgent. Thx
     
    ipohismytown, Feb 23, 2010 IP
  2. hirephpdeveloper

    hirephpdeveloper Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #2
    u need to use the where clause in your sql query and use the respective id for particular image.
     
    hirephpdeveloper, Feb 23, 2010 IP
  3. ipohismytown

    ipohismytown Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    Erm....the database column "prod_image_url" contain "pic1.jpg,pic2.jpg,pic3.jpg" inside because it can insert many picture inside so how i can get the first 1?How to use the where clause, i do not think can use WHERE because the column "prod_image_url" maybe contain information with other name "1.jpg,2.jpg,3.jpg,4.jpg".
     
    ipohismytown, Feb 23, 2010 IP
  4. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?
    $hostName = "localhost"; // Address of the database server
    $databaseName = "try"; // Name of the database
    $dbusername = "root"; // User name
    $dbpassword = ""; // Database password
    $db=mysql_connect("$hostName","$dbusername","$dbpassword") or die('Error, Could not connect to the database');
    mysql_select_db("$databaseName");
    $result=mysql_query("SELECT prod_img_url FROM product");
    while($row=mysql_fetch_array($result))
    {
    $rawimagename=$row['prod_img_url'];
    $imagename=explode(',',$rawimagename);
    foreach($imagename as $key => $value)
    {
    ?>
    <img src="<? echo $value ?>" alt="<? echo $value ?>">
    <?
    }
    }
    ?>

    Check above code....
     
    Om ji Kesharwani, Feb 23, 2010 IP