Page 1 of 1

displaying sql returns

Posted: Sun Oct 17, 2004 6:05 pm
by hward
feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

$sql = "SELECT image
	FROM $table_name 
	 	 ORDER BY image ";
	
$result = @mysql_query($sql,$connection)
	or die("Couldn't execute query.");
 
while ($row = mysql_fetch_array($result)) {
	$image_name = $row['image'];
	
	$display_block .= "
	<img border='1' src='$image_name' width='135' height='100'>
	<p>
	";


}
this is opens my database to get the image names and then the display block displays it when i echo it in the html but i dont want to returns all the images in a single collum going down i would like to do the return with a row of 4 and then the next 4 below that and so on.


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Oct 17, 2004 6:19 pm
by nigma
Do something like:

Code: Select all

$idx = 0;
while ($row=mysql_fetch_array($result)) {
  if (($idx%4)==0) $display_block .= "<br />";
  $display_block .= "<img border='1' src='$image_name' width='135' height='100'>";
  $idx++;
}
For information about the modulus operator: http://us2.php.net/operators.arithmetic

Posted: Sun Oct 17, 2004 6:26 pm
by hward
that displays the first picture for all of them so where i have 50 pictures to display it give me 50 of the first one

Posted: Sun Oct 17, 2004 6:36 pm
by John Cartwright
hward wrote:that displays the first picture for all of them so where i have 50 pictures to display it give me 50 of the first one
Your missing the point, the point is you would do something like

loop
{
if x dividable by 4, add a column, if it is, start a new row

x+1

}

Posted: Sun Oct 17, 2004 6:36 pm
by hward
feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


works now    thanks

Code: Select all

$idx = 0;
while ($row=mysql_fetch_array($result)) {  
if (($idx%4)==0) echo "<br />";  
echo "<img border='1' src='$row[0]' width='135' height='100'>";  $idx++;}

Code: Select all

src='$row[0]'

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Oct 18, 2004 10:12 am
by nigma
:P Excellent. Glad we could help.