dadragon84 Posted May 22, 2015 Share Posted May 22, 2015 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 More sharing options...
cyberRobot Posted May 22, 2015 Share Posted May 22, 2015 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 https://forums.phpfreaks.com/topic/296453-imagestring-foreach-loop/#findComment-1512473 Share on other sites More sharing options...
dadragon84 Posted May 22, 2015 Author Share Posted May 22, 2015 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 https://forums.phpfreaks.com/topic/296453-imagestring-foreach-loop/#findComment-1512478 Share on other sites More sharing options...
cyberRobot Posted May 22, 2015 Share Posted May 22, 2015 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; } ?> Link to comment https://forums.phpfreaks.com/topic/296453-imagestring-foreach-loop/#findComment-1512480 Share on other sites More sharing options...
dadragon84 Posted May 22, 2015 Author Share Posted May 22, 2015 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 https://forums.phpfreaks.com/topic/296453-imagestring-foreach-loop/#findComment-1512481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.