Munch Posted October 6, 2006 Share Posted October 6, 2006 Hi guys,Im new to php and have been working on a image that returns infomation from a mysql database,In mysql i have a list of jobs which are numbered 111, 211, 311 etcWhat i want to do is be able to convert those numbers into the names of the actual job and display the name in the image.Note: Editing the numbers in the database is not a optionThank you for any help that you can provide.Chris Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/ Share on other sites More sharing options...
thedarkwinter Posted October 6, 2006 Share Posted October 6, 2006 HiAm i missing something?Is your table struc something like?jobid | jobname | data111 | something | random211 | blahblah | data311 | etc | herethen just select jobname instead of jobid?if it isn't that is probably what you should be doing...cheers,tdw Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104875 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 I'm assuming that you have the names of the job in your database e.g.[b]Jobs[/b][table][tr][td]ID[/td][td]Number[/td][td]Name[/td][/tr][tr][td]1[/td][td]111[/td][td]Clean Windows[/td][/tr][tr][td]2[/td][td]211[/td][td]Wash Clothes[/td][/tr][tr][td]3[/td][td]311[/td][td]Empty Bins[/td][/tr][/table]If so then yes, it's quite simple.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104876 Share on other sites More sharing options...
Munch Posted October 6, 2006 Author Share Posted October 6, 2006 The only infomation that is in the database except personal infomation is the job numbersIn the DB..Name| Job | Phonejohn | 111 | +44dave| 211 | +44rich | 311 | +44Not in the DB111 = Plumber211 = Electrician311 = JoinerI want to be able to call the infomaton from the database by http://domain.com/job.php?name=Johnthen have the business card shown with name job title andphone numberI hope this clears things up :)Chris Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104879 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 OK, if you don't have the information in the database then you'll need something like an array with the data in.[code]<?php$profession = array(111 => "Plumber", 211 => "Electrician", 311 => "Joiner");$sql = "SELECT job FROM tablename";$result = mysql_query($sql);while ($roles = $mysql_fetch_array($result, MYSQL_ASSOC)){ extract($roles); echo "{$job} => {$profession[$job]}";}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104884 Share on other sites More sharing options...
Munch Posted October 6, 2006 Author Share Posted October 6, 2006 hi huggie,how would i display that script in a imagecreatefrompng image please?sorry to be a painchris Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104910 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 You wouldn't... You just put this code around any image creation code and then use the variables with the image functions, something like this:[code]<?php$profession = array(111 => "Plumber", 211 => "Electrician", 311 => "Joiner");$sql = "SELECT job FROM tablename";$result = mysql_query($sql);while ($roles = $mysql_fetch_array($result, MYSQL_ASSOC)){ extract($roles); $text = $profession[$job]; // All your image code goes here. You should use imagettftext() to add the text to the image // and you'll want to provide the last argument, which is string as $text}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104932 Share on other sites More sharing options...
Munch Posted October 6, 2006 Author Share Posted October 6, 2006 This is what i have so far...[b]staff.php[/b][code]<?php error_reporting(0); include ("staff.inc.php"); $name = $_GET['name']; if ($name == null || $name == '') { $name = ""; }$link = mysql_connect($MySQLSrv, $MySQLUser, $MySQLPass);if (!$link) { die('Could not connect to MySQL! : ' . mysql_error());}$db_selected = mysql_select_db($MySQLDB, $link);if (!$db_selected) { die ('Could not find the DB : ' . mysql_error());}if ($name != "") {$result = mysql_query("SELECT name, job, phone FROM staff WHERE name = '{$name}'");if (!result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result); header("Content-type: image/png"); $im = imagecreatefrompng("$pngimage"); $cBlack = imagecolorallocate($im, 0, 0, 0); if ($name != "") { imagestring($im, 5, 10, 10, 'Name: ' . $row[0], $cBlack); imagestring($im, 5, 10, 30, 'Job: ' . $row[1], $cBlack); imagestring($im, 5, 10, 50, 'Phone: ' . $row[2], $cBlack); imagepng($im); imagedestroy($im); } }?>[/code][b]staff.inc.php[/b][code]<?php$pngimage = "staff.png";$MySQLSrv="localhost";$MySQLDB="test";$MySQLUser="root";$MySQLPass="";?>[/code]i was typin this out while you were posting.. ill ready ur post now :) Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104933 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 OK, change this:[code]<?phpif ($name != "") { imagestring($im, 5, 10, 10, 'Name: ' . $row[0], $cBlack); imagestring($im, 5, 10, 30, 'Job: ' . $row[1], $cBlack); imagestring($im, 5, 10, 50, 'Phone: ' . $row[2], $cBlack); imagepng($im); imagedestroy($im);}?>[/code]To this:[code]<?phpif ($name != "") { imagestring($im, 5, 10, 10, 'Name: ' . $row[0], $cBlack); $profession = array(111 => "Plumber", 211 => "Electrician", 311 => "Joiner"); $job_id = $row[1]; $job = $profession[$job_id]; imagestring($im, 5, 10, 30, 'Job: ' . $job, $cBlack); imagestring($im, 5, 10, 50, 'Phone: ' . $row[2], $cBlack); imagepng($im); imagedestroy($im);}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104941 Share on other sites More sharing options...
Munch Posted October 6, 2006 Author Share Posted October 6, 2006 thank you very much :) its working how i wanted it to now :D Quote Link to comment https://forums.phpfreaks.com/topic/23161-php-mysql-editing-returned-values/#findComment-104952 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.