$query = ” SELECT
*
FROM
udowers
“;
$mysqlquery = mysql_query($query);
/* IMAGE CREATION */
$lines = mysql_num_rows($mysqlquery);
// Create a image
$im = imagecreate(400, 12 * $lines);
// Set colors
$background = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 255, 0, 0);
/* END IMAGE CREATION */
if($mysqlquery){
while($row = mysql_fetch_assoc($mysqlquery)){
imagestring($im, 3, 5, $height += $lines * 12, $row['udower'], $textcolor);
}
}
else
{
imagestring($im, 3, 5, 5, 'MySQL Error', $textcolor);
}
/* IMAGE CREATION */
// Output the image
header('Content-type: image/png');
// Show the image
imagepng($im);
imagedestroy($im);
/* END IMAGE CREATION */
Im trying to get all the names on the column udower from the table udowers, but this doesn’t work. It doesn’t display anything at all. Can you guys help me please?
On this line
You are placing the pointer to the end of the results. Thus, inside your
whileloop it won’t fetch any more results.I think you are looking for the number of rows returned on that line, so you should do:
Also, the line will always be the same, because you do
12 * $linesalways. You are creating a variable$height = 12 * $lines;, but you are not using it.When you create that variable you should assign it to
0, like so:Then, when you add the string to your image you should do:
Now that you changed the height to
0, you must adjust for the image height too: