liamoco Posted September 30, 2010 Share Posted September 30, 2010 I have a string which is a list of user id's like "44/5/6/67/7/88/56/76/9/90/65/74/8/68". I explode this string and put them into an array, but now I have a problem of getting the users first names from the database by using the id's and putting them in alphabetical order. How can I do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/ Share on other sites More sharing options...
Adam Posted September 30, 2010 Share Posted September 30, 2010 Implode the IDs within an IN condition in the query, then order by the first name: $sql = "select id, first_name from users where id in ('" . implode("', '", $ids) . "') order by first_name"; Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/#findComment-1117669 Share on other sites More sharing options...
liamoco Posted September 30, 2010 Author Share Posted September 30, 2010 This is what I am trying... $friend_id_array = $friend_id_array.$friend_id."/".$more_friend_id; $friend_id_array = explode('/', $friend_id_array); $query_online = mysql_query("SELECT loggedin, fname, mname, lname FROM users WHERE id in ('" . implode("'/'", $friend_id_array) . "' ORDER BY fname"); //get loggedin and names LINE 162 while($row = mysql_fetch_assoc($query_online)) { $loggedin = $row['loggedin']; $fname = $row['fname']; if($loggedin == "1") $online_count++; } I cannot see what I am doing wrong, i have commented out to show line 162 in the code above Fatal error: Call to undefined function impode() in J:\mowes\www\squiblo\functions.php on line 162 Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/#findComment-1117681 Share on other sites More sharing options...
kenrbnsn Posted September 30, 2010 Share Posted September 30, 2010 The line you posted has the correct function name implode, but the error says you used "impode" which is incorrect. Which is it? Ken Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/#findComment-1117683 Share on other sites More sharing options...
liamoco Posted September 30, 2010 Author Share Posted September 30, 2010 @ken, i noticed as soon as i posted it, ive change it, but still not working, im getting this error, although i have double checked all the field names are correct... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in J:\mowes\www\squiblo\functions.php on line 163 Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/#findComment-1117684 Share on other sites More sharing options...
liamoco Posted September 30, 2010 Author Share Posted September 30, 2010 I was missing a closing bracket in the query, now I am getting no errors, but not the correct output, the output being the $online_count Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/#findComment-1117688 Share on other sites More sharing options...
mikosiko Posted September 30, 2010 Share Posted September 30, 2010 echo $loggedin and compare the result with what are you doing in your if($loggedin == "1") Quote Link to comment https://forums.phpfreaks.com/topic/214845-get-users-from-db-in-alphabetical-order/#findComment-1117691 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.