johnrb87 Posted December 13, 2010 Share Posted December 13, 2010 Hi I need to do a SELECT query like $query = "SELECT name FROM myusers WHERE myidnum = ".$_SESSION['myid'].""; and put the results into an array like $myusers = array("David","John","Lucy","Sarah"); But I cannot figure out how to do this Can anyone help? Thanks Link to comment https://forums.phpfreaks.com/topic/221448-array-from-select-query/ Share on other sites More sharing options...
jamesxg1 Posted December 13, 2010 Share Posted December 13, 2010 $query = "SELECT name FROM myusers WHERE myidnum = ".$_SESSION['myid'].""; $run = mysql_query($query); while($row = mysql_fetch_array($run)) { echo '<pre>' . print_r($row, true) . '</pre>'; } James. Link to comment https://forums.phpfreaks.com/topic/221448-array-from-select-query/#findComment-1146426 Share on other sites More sharing options...
mikhell Posted December 13, 2010 Share Posted December 13, 2010 try this $query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '.$_SESSION['myid'].'"); $userArray = array; while($user = mysql_fetch_array($query)) { array_push($userArray , $user); } Link to comment https://forums.phpfreaks.com/topic/221448-array-from-select-query/#findComment-1146465 Share on other sites More sharing options...
laffin Posted December 13, 2010 Share Posted December 13, 2010 cant use ' in a " string for the keyname unless variable name is encapsulated with curly braces. and u missed the removal of the concatenation operator. all these would be valid query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '".$_SESSION['myid']."'"); query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '$_SESSION[myid]'"); query = mysqli_query($connexion, "SELECT name FROM myusers WHERE myidnum = '{$_SESSION['myid']}'"); Link to comment https://forums.phpfreaks.com/topic/221448-array-from-select-query/#findComment-1146467 Share on other sites More sharing options...
johnrb87 Posted December 13, 2010 Author Share Posted December 13, 2010 thanks So how can I translate the output to feed into $myusers = array("David","John","Lucy","Sarah"); ? Link to comment https://forums.phpfreaks.com/topic/221448-array-from-select-query/#findComment-1146493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.