Hi there,
Hoping that I can get some help on a GD Coding issue that I've been struggling with for the last 2 days ... (searched everywhere on the net, but cant find an answer). Basically what I need to achieve is,
Establish a connection to my MySQL db, retrieve all the records and display them on the page. Each record contains data from the following fields: UniqueID, Category and Name
For each record (containing the fields listed above) that I display on the page, I also want to dynamically create an image using the GD function. The text that needs to appear on the dynamic image needs to be pulled from the database (using the Name field value).
Can someone please provide assistance on how to achieve this? I have made many attempts, but none have yet been successful. Here is my latest attempt (see #3 below). Not sure if this method is most appropriate or not???
1) This is the code for the php page (RetrieveAllRecords.php) that I use to retrieve all records from a MySQL db. I have tested this page and it works!
<html>
<body>
<head>
<title>This is my Retrieve Records Page !*</title>
</head>
<?php
$dbhost = 'mysql.xxx.com.au;
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'databasename';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query = "SELECT * FROM fonts";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "UniqueID :{$row['UniqueID']} <br>" .
"Category : {$row['Category']} <br>" .
"Name : {$row['Name']} <br><br>";
}
?>
</body>
</html>
2) This is another php page (GD.php) that I use to dynamically create an image (using a specified Font and TextString) using the GD command in PHP. I have tested this page and it works!
<?php
header("Content-type: image/png");
$im = imagecreate(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$path2fonts = $DOCUMENT_ROOT."/ttf";
$font = 'asenine';
$TextString = 'This is the TextString to display for the font';
imagettftext($im, 20, 0, 10, 20, $black, $path2fonts."/".$font, $TextString);
imagepng($im);
imagedestroy($im);
?>
3) Its only when I try to combine the contents/usage of both these pages, that I run into problems.
The code / page below returns errors of:
"Parse error: parse error, expecting ','' or';'' in D:\hshome\ animatio\ animationhut.com\ Combined.php on line 24"
This is the combined page (Combined.php) that I use:
<html>
<body>
<head>
<title> Combined Retrieve Records Page + GD Page </title>
</head>
<?php
$dbhost = 'mysql.xxx.com.au;
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'databasename';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query = "SELECT * FROM fonts";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "UniqueID :{$row['UniqueID']} <br>" .
"Category : {$row['Category']} <br>" .
"Name : {$row['Name']} <br>".
"Image of Font : <img src="GD.php"> <br><br>";
}
?>
</body>
</html>
thanks again everyone !!!!
🙂