rubing Posted March 22, 2008 Share Posted March 22, 2008 How do I assign the contents of a resource (e.g. results of a mysql query) to a variable. I attempted using $var = echo $result; but did not work. thanks Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/ Share on other sites More sharing options...
BlueSkyIS Posted March 22, 2008 Share Posted March 22, 2008 you need to use a mysql function to pull the values into an array, for instance: $row = mysql_fetch_array($result); then $row is an array of the values for that record, with the keys being the column names, e.g., $user_name = $row['userName']; Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498322 Share on other sites More sharing options...
Orio Posted March 22, 2008 Share Posted March 22, 2008 What exactly do you want to do? You want to convert the resource to a string? For that use serliaze(). Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498323 Share on other sites More sharing options...
rubing Posted March 22, 2008 Author Share Posted March 22, 2008 I am forwarding my emails to a php script and then executing a query to my database. I want to mail the results using mail() This has been very tricky to do, b/c if there is ever any standard output the email bounces with failed delivery. Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498350 Share on other sites More sharing options...
BlueSkyIS Posted March 22, 2008 Share Posted March 22, 2008 you need to use a mysql function to pull the values into an array, for instance: $row = mysql_fetch_array($result); then $row is an array of the values for that record, with the keys being the column names, e.g., $user_name = $row['userName']; Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498355 Share on other sites More sharing options...
rubing Posted March 22, 2008 Author Share Posted March 22, 2008 hmmmm....so how can i convert all of the resulting records into a string type variable ??? Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498366 Share on other sites More sharing options...
rubing Posted March 22, 2008 Author Share Posted March 22, 2008 can i do something like this??? while ($row = mysql_fetch_array($result)) {global $message $message .= print_r($row,true); } Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498368 Share on other sites More sharing options...
rubing Posted March 22, 2008 Author Share Posted March 22, 2008 yup worked! Thanks Rubing You're the best! blueskyis and orio are cool too Link to comment https://forums.phpfreaks.com/topic/97383-convert-resource-to-variable/#findComment-498375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.