Jump to content

Imagestring foreach loop


dadragon84

Recommended Posts

I am trying to add a new line within a foreach loop using imagestring, but it keeps showing the information on the same line Here is the image and you can see the mistake I dont need to point it out Image Link

<?php

if (count($rows) == 0) {
    imagestring($image, $fontsize, $leftside, 90, "NO JOBS DETECTED", $font_white);
}

foreach($rows as $key=>$row) {
    $query = "
    SELECT username FROM users";
    $query_params = array(':id' => $row['driver']);
    $query .= "WHERE id = :id";

    try {
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    } catch(PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }

    $driver = $stmt->fetch();
    $driver = $driver['username'];

    imagestring($image, $fontsize, $leftside, 100, "Top 5 Drivers", $font_red);
    imagestring($image, $fontsize, $leftside, $linedown, ($key+1).'..' . $driver, $font_red);
}
Link to comment
Share on other sites

The fourth argument for imagestring(), where you have $linedown, should represent the y-position for your text. As far as I can tell, that value isn't being changed for each iteration of the loop.

 

Also, I would image that the call to imagestring() for the "Top 5 Drivers" header should be made outside the loop. Otherwise the header is added for every entry in $rows.

Link to comment
Share on other sites

The fourth argument for imagestring(), where you have $linedown, should represent the y-position for your text. As far as I can tell, that value isn't being changed for each iteration of the loop.

 

Also, I would image that the call to imagestring() for the "Top 5 Drivers" header should be made outside the loop. Otherwise the header is added for every entry in $rows.

ok I changed the top 5 drivers and the $linedown is set somewhere else above but its still not applying a new line

how do I set $linedown to add a new number for each loop

this is the variable that is set curently

$linedown = 15;
Link to comment
Share on other sites

If you wanted to move the starting point (y-position) down by 15 every time, you could do something like this:

<?php
//...


     imagestring($image, $fontsize, $leftside, $linedown, ($key+1).'..' . $driver, $font_red);
 
    //UPDATE Y-POSITION FOR NEXT LOOP ITERATION
    $linedown += 15;
}
?>
Edited by cyberRobot
Link to comment
Share on other sites

 

If you wanted to move the starting point (y-position) down by 15 every time, you could do something like this:

<?php
//...


     imagestring($image, $fontsize, $leftside, $linedown, ($key+1).'..' . $driver, $font_red);
 
    //UPDATE Y-POSITION FOR NEXT LOOP ITERATION
    $linedown += 15;
}
?>

THANK YOU VERY MUCH

That worked

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.