Forum Moderators: coopster

Message Too Old, No Replies

PHP GD Help

         

nedloh

8:37 am on Aug 28, 2007 (gmt 0)

10+ Year Member



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

{

$count = mysql_num_rows($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);
}}
?>

I know its not commented but don't complain. Anyone can read that and if they can't they shouldn't be.(I normally code LOTS but i wacked this together quickly).

As you can see i suck at PHP GD

dreamcatcher

8:41 am on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi nedloh,

Put the following after your opening PHP tag:

error_reporting(E_ALL);

See if that throws any clues.

dc

nedloh

8:51 am on Aug 28, 2007 (gmt 0)

10+ Year Member



It doesn't error. but just keeps using the first fields desc E.G, the first field's description is Home. And it will show that on each image instead of looping through. But ill try that error reporting. annnd, Nope. Nothing errorwise(Obviously)

Habtom

8:56 am on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try taking out the count outside the loop

> $count = mysql_num_rows($query123);

nedloh

9:03 am on Aug 28, 2007 (gmt 0)

10+ Year Member



I know :D I added that to try and loop till no rows where left, but it wasn't working before that

whoisgregg

1:32 pm on Aug 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't header() out multiple files. It just won't work. Plus, the error reporting is hidden from you because it is ignored by the browser (wrong type of data for the headers sent).

In order to output multiple images, you'll really need either call the script for each image you want or you need to output the images to files then include the cached images with <img> tags.