ricktee76 Posted May 15, 2008 Share Posted May 15, 2008 i'm trying to convert a database which currently store employees and thier jod description like this John Smith -- Operations manager i have been able to get the data from the database and using the explode function $result = mysql_query('SELECT * FROM employees WHERE id=876'); if (!$result) { die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_assoc($result)) { $employee =$row['employee']; } echo"<pre>"; $array = print_r(explode('--', $employee,2)); echo"</pre>"; which gives me this result Array ( [0] => John Smith [1] => Operations Manager ) $name = FIRSTVALUE; $title = SECONDVALUE; i would like to display these like: echo "<BR>"; echo "Employee: "; //THE Array[0] value echo "<BR>"; echo "Job Title: "; //THE Array[1] value the display is a temporary measure purely for debugging purposes eventually the array contents will be re-inserted back into two database table. Arrays are a new thing for me i need to extract array value[0] and value [1] as seperate strings Link to comment https://forums.phpfreaks.com/topic/105749-get-array-string-after-explode/ Share on other sites More sharing options...
The Little Guy Posted May 15, 2008 Share Posted May 15, 2008 echo "<BR>"; echo "Employee: ".$array[0]; //THE Array[0] value echo "<BR>"; echo "Job Title: ".$array[1]; //THE Array[1] value Link to comment https://forums.phpfreaks.com/topic/105749-get-array-string-after-explode/#findComment-541814 Share on other sites More sharing options...
ricktee76 Posted May 15, 2008 Author Share Posted May 15, 2008 thanks TLG the suggestion you gave wasnt working so i played around and the problem seemed to be the print_r function $array = print_r(explode('--', $employee,2)); i change this to $array = explode('--', $employee,2); and it worked, thanks for pointing me in the right direction. Link to comment https://forums.phpfreaks.com/topic/105749-get-array-string-after-explode/#findComment-541855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.