Jump to content

mysql query 'GROUP_CONCAT' - need help


carlosp
Go to solution Solved by Psycho,

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Solution

$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 by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.