Jump to content

get array string after explode


ricktee76

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.