View Full Version : PHP GD Loops

08-28-2007, 01:38 PM
I have a piece of code for a nav bar that will create dynamic images that are linked on the main page. But, the problem is that it wont loop through different descriptions of the link

Here is the code


$sql123 = "SELECT * FROM nav ORDER by pos";

$query123 = mysql_query($sql123);


while($row = mysql_fetch_array($query123))


$text = $row['desc'];

$pic=ImageCreate(60,30); //(width, height)



ImageFilledRectangle($pic, 0, 0, 500, 30, $col2);

ImageString($pic, 3, 5, 8, $text, $col1);

Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

Header("Content-type: image/jpeg");


As you can see i suck at PHP GD

08-28-2007, 01:49 PM
Each image on a web page requires its' own <img src="url_of_the_image" alt=""> tag. You can only output one image in each <img ... > tag. Looping [edit: and outputting multiple dynamic images at one time] won't work. If you post your nav bar/menu code that contains the <img ...> tag(s), someone can probably help with what you need to change.

08-28-2007, 03:02 PM

while($row = mysql_fetch_array($query123))


$text = $row['desc'];

Using while($row = mysql_fetch_array()) means that $row is overwritten every loop, so $row['desc'] would just be the last result, if that is what you meant to do then there is is the much more efficient way of limiting the SQL query.