freakness883 Posted July 13, 2006 Share Posted July 13, 2006 I have the following code:[quote]<?php $query3 = "SELECT members FROM groups WHERE g_id='".$id."'";echo "$query3"; $result3 = mysql_query("SELECT members FROM groups WHERE g_id='1'");$row = mysql_fetch_row($result3); $pieces = explode(" ", $row);echo $pieces[0];echo $pieces[1];if (in_array("bbaker", $pieces)) { echo "Got bbaker";}else{ echo "nope";}[/quote][b]echo "$query3"[/b] is printing out the proper select statement -- runnning the statement manually in MySQL gets me the record "bbaker bbarker". But when I echo [b]$pieces[0][/b] and [b]$pieces[1][/b] I get the output [b]Array[/b] for both. I was hoping for bbaker and bbarker. And also I'm returning false on the condition [b]in_array("bbaker", $pieces)[/b]. Something's wrong with my SQL query. Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/14538-problem-using-the-explode-function/ Share on other sites More sharing options...
Kurt Posted July 13, 2006 Share Posted July 13, 2006 It's because $row itself is an array, and you can't explode an array, only a string. Quote Link to comment https://forums.phpfreaks.com/topic/14538-problem-using-the-explode-function/#findComment-57646 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2006 Share Posted July 14, 2006 You want to use implode on the $row[code]<?php echo implode(' ',$row); ?>[/code]Or you can just use echo on the $row entries:[code]<?php echo $row[0] . ' ' . $row[1]; ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/14538-problem-using-the-explode-function/#findComment-57662 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.