Jump to content

for loop


Woodburn2006

Recommended Posts

i have a database with fields named img1, img2, img3 up to img8. some of these fields hold paths to images and some of them have a value of 'x' just to show there is no image present.

 

i am making a page that shows these images but i need it to only show the fields that have an image in it, i have put together a simple bit of script but i was wondering if there is an easier way of doing it using a for loop or omething similar.

 

heres what i have got:

 

	if($img1 != "x"){echo "<img src='$img1' width='150' border='0'><br /><br />";}
if($img2 != "x"){echo "<img src='$img2' width='150' border='0'><br /><br />";}
if($img3 != "x"){echo "<img src='$img3' width='150' border='0'><br /><br />";}
if($img4 != "x"){echo "<img src='$img4' width='150' border='0'><br /><br />";}
if($img5 != "x"){echo "<img src='$img5' width='150' border='0'><br /><br />";}
if($img6 != "x"){echo "<img src='$img6' width='150' border='0'><br /><br />";}
if($img7 != "x"){echo "<img src='$img7' width='150' border='0'><br /><br />";}
if($img8 != "x"){echo "<img src='$img8' width='150' border='0'><br /><br />";}

 

any help would be much appreciated

Link to comment
https://forums.phpfreaks.com/topic/105037-for-loop/
Share on other sites

You ought to consider using a separate table in your database for your images, rather than having all these different fields in the same table.

 

Try reading up on database normalization. Maybe this post will help you start:

http://www.phpfreaks.com/forums/index.php/topic,126097.0.html

Link to comment
https://forums.phpfreaks.com/topic/105037-for-loop/#findComment-537664
Share on other sites

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.