PHP/SQL - displaying $row in a different way?

Associate
Joined
26 Jul 2005
Posts
352
ok so i've coded my own image gallery that suits my needs... and im currently displaying each image like this...

Picture%201.jpg


its not very affective... uses lots of space to display images and displays too much info than it really needs.

if the image column in the SQL database after the query is $row[4] how would i get it to display something like

IMAGE1 IMAGE2 IMAGE3

IMAGE4 IMAGE5 IMAGE6


does this make sense? i can set it out so i have the images going horizontal or vertical but not in a grid.
 
that makes no sense as to what i asked :p

im wanting to turn this

IMAGE1 - Description
IMAGE2 - Description
IMAGE3 - Description
IMAGE4 - Description

into

IMAGE1 IMAGE2 IMAGE3

IMAGE4 IMAGE5 IMAGE6

when the variable for the image is $row[4].
 
Something like:

PHP:
while ($mysql_counter < $num) {
	$img=row[4]; 

	if ($rowcounter == 0) {
	  echo "<tr valign=\"middle\">\n";
	}
	 
	echo "<td><img src=$img /></td>\n";
	$rowcounter++;
	if ($rowcounter == 3)
	{$rowcounter = 0; echo "</tr>";}
	
	
	
	$mysql_counter++;}



if ($rowcounter != 0) {
	  $thatsit = "Sorry, we ran out of ideas!";
 while ($rowcounter < 3) {
	  
	  echo "<td></td>\n";
	  $thatsit = "";
$rowcounter++;	  
	}
	echo "</tr>\n";
}
???
(not tested so could [edit - it is] be wrong but you get the idea.... [needs modification still but i'm tired!])
 
Last edited:
so to give a bit more info ive got something like this:

PHP:
actually ignore that it was parp and made little sense

thats a rough and simplified version of what ive currently got - creating a table with a different entry on each row. now instead of creating a new row for each entry i want one entry per cell in say a 3 x 3 grid.
 
Last edited:
It does fit with what you want, though :confused:

Code:
<style type="text/css">
.image { width:250px; height:300px; float:left; }
</style>

<?php

for ( $i = 0; $i < count($row); $i++ )
    echo "<div class='image'><img src='{$row[$i]['image']}' alt='' /></div>\n";

Which will result in:

Code:
Image 1		Image 2		Image 3
Image 4		Image 5		Image 6

Presuming the viewport is ~750px wide. If you want to manually insert a break after the third row, then use:

Code:
for ( $i = 0; $i < count($row); $i++ ) {
    echo "<div class='image'><img src='{$row[$i]['image']}' alt='' /></div>\n";
    if ( ( $i + 1 ) % 3 == 0 )
        echo '<br style="clear:left;" />';
}
 
thanks all, i'll have a play later on... the bit of php i know it self taught and unless ive used it on my own website i dont know it...

this is something which isnt covered in tutorials etc..
 
ahhh in the end i worked out a soloution: brute force - its not pretty but it works

just created a different query for each row of the table - and its helped me along with the bit im worrying about which i can now do :D

cheers all
 
Back
Top Bottom