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
https://forums.phpfreaks.com/topic/296453-imagestring-foreach-loop/
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.

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;

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;
}
?>

 

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

Archived

This topic is now archived and is closed to further replies.

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