how can i do this

Discussion in 'PHP' started by dougvcd, Jun 3, 2007.

  1. #1
    i have this code which reads off a database
    what i would like to do is display an image after each line
    if i put a folder on server called pics put all pics in the folder pics named 1,2,3 etc how do i call each one and display it

    $result = mysql_query("SELECT * FROM exchange");
    
    echo "<table border='1'align=center>
    <tr>
    <p align='center' class='bodytext'>
    <th>park-name</th>
    <p align='center' class='bodytext'>
    <th>park-location</th>
    <p align='center' class='bodytext'>
    <th>caravan-details</th>
    </tr>";while($row = mysql_fetch_array($result))
    {
     echo "<tr>";
      echo "<td>" . $row['parkname'] . "</td>";
      echo "<td>" . $row['parklocation'] . "</td>";
      echo "<td>" . $row['caravandetails'] . "</td>";
      echo "</tr>";
      }
      echo "</table>";mysql_close($con);
    PHP:
    cheers
    Doug
     
    dougvcd, Jun 3, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    how do the pictures differentiate themselves from eachother with numbers in the first place ??

    seeing the output of that page and a link to the folder of images might explain it better than words can.
     
    krakjoe, Jun 3, 2007 IP
  3. CygnetGames

    CygnetGames Peon

    Messages:
    43
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You would need to get PHP to write a HTML img tag:

    echo '<img src="' . $imgURL . '" />';
    PHP:
    Where $imgURL is the path to your image ("pics/1.jpg" or whatever you are calling them).
    Also don't forget alt/width/height in the img tag if you want them.
     
    CygnetGames, Jun 3, 2007 IP
  4. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    this may be simple to most peps
    but not to me need more help to do it
    cheers
    Doug
     
    dougvcd, Jun 3, 2007 IP
  5. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Where do you want the image to display? inside the while loop or outside the table?
     
    Vbot, Jun 3, 2007 IP
  6. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    well, if the pics name is like you said, then you can try this.
    $count=0;
    while($row = mysql_fetch_array($result))
    {
    	$count++;
    	echo "<tr>";
    	echo "<td><img src='pics/$count.jpg'></td>";
    	echo "<td>" . $row['parkname'] . "</td>";
    	echo "<td>" . $row['parklocation'] . "</td>";
    	echo "<td>" . $row['caravandetails'] . "</td>";
    	echo "</tr>";
    }
    echo "</table>";
    mysql_close($con);
    PHP:
     
    Vbot, Jun 4, 2007 IP
  7. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i want a picture and beside it a table with info
    cheers
    Doug
     
    dougvcd, Jun 4, 2007 IP
  8. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    cheers for that will give it a try
    Doug
     
    dougvcd, Jun 4, 2007 IP
  9. Seiya

    Seiya Peon

    Messages:
    4,666
    Likes Received:
    404
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That should work, if it doesn't make sure you check your permissions :)
     
    Seiya, Jun 4, 2007 IP
  10. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    this is what i have but pics dont show any ideas
    cheers
    Doug

    <p align='center' class='bodytext'>
    <th>caravan-details</th>
    $count=0;
    </tr>";while($row = mysql_fetch_array($result))
    {
       $count++;
       echo "<tr>";
       echo "<td>" . $row['name'] . "</td>";
       echo "<td>" . $row['email'] . "</td>";
       echo "<td>" . $row['parkname'] . "</td>"; 
       echo "<td>" . $row['parklocation'] . "</td>"; 
       echo "<td>" . $row['caravandetails'] . "</td>"; 
       echo "<td><img src='pics/$count.jpg'></td>";
         
       echo "</tr>";
    }
    echo "</table>";
    PHP:
    where it says pics/$count.jpeg should the word pic be in there some where
     
    dougvcd, Jun 4, 2007 IP
  11. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    ok all sorted now
    thanks to all
    Cheers
    Doug
     
    dougvcd, Jun 4, 2007 IP