...

View Full Version : PHP GD Loops



nedloh312
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


<?
include('includes/config.php');

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

$query123 = mysql_query($sql123);

if($query123){

while($row = mysql_fetch_array($query123))

{

$text = $row['desc'];

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

$col1=ImageColorAllocate($pic,0,0,0);

$col2=ImageColorAllocate($pic,255,255,255);//colour1

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");

ImageJPEG($pic);
}}
?>

As you can see i suck at PHP GD

CFMaBiSmAd
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.

Mwnciau
08-28-2007, 03:02 PM
if($query123){

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum