Jump to content

[SOLVED] Why does php returning only one row of data?


pneudralics

Recommended Posts

Can't figure why php is only returning one row of data.

 

//Website url
$websiteurl = WEBSITEURL;
//Retrieve gallery info
$galleryselect = "SELECT * FROM gallery ORDER BY id ASC";

if ($galleryresult = mysql_query ($galleryselect)) {
while ($row = mysql_fetch_array ($galleryresult)) {
$gallery = $row['image'];
}
}
?>

<table width="800" align="center">
    <tr>
        <td width="100%" align="center">
<?php
echo '<img src="'.$websiteurl.'/images/gallery/'.$gallery.'">';
?>         
        </td>
</tr>
</table>

Your HTML code needs to be within your while loop otherwise only the last result will be displayed.

<table width="800" align="center">
    <tr>
        <td width="100%" align="center">
<?php

//Website url
$websiteurl = WEBSITEURL;
//Retrieve gallery info
$galleryselect = "SELECT * FROM gallery ORDER BY id ASC";

if ($galleryresult = mysql_query ($galleryselect))
{
    while ($row = mysql_fetch_array ($galleryresult))
    {
        $gallery = $row['image'];

        echo '<img src="'.$websiteurl.'/images/gallery/'.$gallery.'" />';
    }
}
?>
        </td>
   </tr>
</table>

TG

Your HTML code needs to be within your while loop otherwise only the last result will be displayed.

<table width="800" align="center">
    <tr>
        <td width="100%" align="center">
<?php

//Website url
$websiteurl = WEBSITEURL;
//Retrieve gallery info
$galleryselect = "SELECT * FROM gallery ORDER BY id ASC";

if ($galleryresult = mysql_query ($galleryselect))
{
    while ($row = mysql_fetch_array ($galleryresult))
    {
        $gallery = $row['image'];

        echo '<img src="'.$websiteurl.'/images/gallery/'.$gallery.'" />';
    }
}
?>
        </td>
   </tr>
</table>

 

THanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.