carlosp Posted March 24, 2013 Share Posted March 24, 2013 here's what i want to do: i have a table which has id's and i want to select them in one query, then put them in an array... table example: id name surname 1 john doe 2 johnny tacev . . 19384 travis malega i tried this: $query = "SELECT GROUP_CONCAT(id) AS id_coll FROM table ORDER BY id DESC"; $result = mysql_query($query) or die ("no query"); while($row = mysql_fetch_assoc($result)){ $cs = implode(", ", $row); } it works but only for the first 256 rows... i can't change server settings... please help me with this thanks! PS: i hope i posted in the right section Quote Link to comment Share on other sites More sharing options...
carlosp Posted March 24, 2013 Author Share Posted March 24, 2013 here's what i want to do: i have a table which has id's and i want to select them in one query, then put them in an array... table example: id name surname 1 john doe 2 johnny tacev . . 19384 travis malega i tried this: $query = "SELECT GROUP_CONCAT(id) AS id_coll FROM table ORDER BY id DESC"; $result = mysql_query($query) or die ("no query"); while($row = mysql_fetch_assoc($result)){ $cs = implode(", ", $row); } it works but only for the first 256 rows... i can't change server settings... please help me with this, it doesn't matter if i need to change the query in any other way. i just need to have the id's in an array (1,2,3,......,19384) thanks! PS: i hope i posted in the right section Quote Link to comment Share on other sites More sharing options...
haku Posted March 24, 2013 Share Posted March 24, 2013 You don't need GROUP_CONCAT for this. Just select ID normally, then loop through the results and put them into an array. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 24, 2013 Share Posted March 24, 2013 But, the reason you are having a problem is that you are using GROUP_CONCAT() but you don't have a GROUP BY to group on. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 24, 2013 Share Posted March 24, 2013 By row 256 you have probably hit the 1000 char size limit Quote Link to comment Share on other sites More sharing options...
carlosp Posted March 24, 2013 Author Share Posted March 24, 2013 thank you all for replying, could you please give me an example of selecting all the id's and put them into an array? one which works, because i couldn't build one until now.... Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted March 24, 2013 Solution Share Posted March 24, 2013 (edited) $query = "SELECT id FROM table ORDER BY id DESC"; $result = mysql_query($query) or die ("no query"); $idsArray = array(); while($row = mysql_fetch_assoc($result)) { //Add each ID as a new element in the array $idsArray[] = $row['id']; } //Output the array to verify echo "<pre>" . print_r($idsArray, 1) . "</pre>"; Edited March 24, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
carlosp Posted March 24, 2013 Author Share Posted March 24, 2013 thanks for your reply's just fixed this morning the query... Quote Link to comment 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.