Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: PHP GD Loops

  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP GD Loops

    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
    PHP 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($pic0050030$col2);

    ImageString($pic358$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

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    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.
    Last edited by CFMaBiSmAd; 08-28-2007 at 12:53 PM. Reason: clarification of looping
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •