Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display image on specified row and column

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Okay I'm looking for a solution to display the pictures bases on specified row and column,say 5 rows and 5 columns per page for my image gallery.I dunno how to make it since I'm using array to retrieve image stored in database.

Here's my dummy code causing weird output:
.......
........
...
while($i=mysql_fetch_array($result)){
for($row=0;$row<6;$row++){
print(&quot;<tr>&quot;);
for($column=0;$column<6;$column++){
print(&quot;<td>$i['image']</td>&quot;);
}
print(&quot;</tr>&quot;);
}
}
.....
.....
So, any solution for this? Shall I change my way of fetching image or what? Helps and
suggestions will be much appreciated. Again thank you very much.
 
I'll bet the weird output is that it puts the same image in every TD element. You have nowhere near enough calls to mysql_fetch_array.

mysql_fetch_array pulls one row of the recordset generated by your select statement each time it is called. You are only calling that function once for every TD element you print.

I'd recommend your putting the mysql_fetch_array statement inside your innermost for loop. Also, before your outmost for loop, I'd suggest your using mysql_num_rows to determine how many images you're pulling out of the table and use that number to limit your printing the image data.

Something along the lines of:

<your select statement happens here>

$rowcount = mysql_num_rows($result);
for($row=0;$row<6;$row++)
{
print(&quot;<tr>&quot;);
for($column=0;$column<6;$column++)
{
if ($row * 5 + $column < $rowcount)
{
$i = mysql_fetch_array($result);
print(&quot;<td>$i['image']</td>&quot;);
}
else
{
print(&quot;<td></td>&quot;);
}
}
print(&quot;</tr>&quot;);
}
 
$col=0; // start at 0, we never need to reset as we check it divides by 5
print(&quot;<tr>&quot;); //start your first cell (check for content first)

while($i=mysql_fetch_array($result)){

if($col %5){ // if column is 5th, terminate and start a new row
echo &quot;<td>$i['image']</td></tr><tr>&quot;;
$col++;
}else{ // draw a normal cell
echo &quot;<td>$i['image']</td>&quot;;
$col++;
}
echo &quot;<tr>&quot;;

}
***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top