Jump to content

mysql query 'GROUP_CONCAT' - need help


carlosp

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
https://forums.phpfreaks.com/topic/276075-mysql-query-group_concat-need-help/
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


$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>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.