Jump to content

Query results to an array


cleibesouza

Recommended Posts

This is got to be pretty simple, still I can figure it out.
How can I dump the results of a query into an array so I can separate the results and use them on another query?

Below is my code

[code]SELECT activities_id
FROM participation
WHERE users_id = '$userID'";

$participationResults = mysql_query($participationQuery, $connection) or die (mysql_error());
$partNumResults = mysql_num_rows($participationResults);

if($partNumResults)
{
  for($y = 0; $y < $partNumResults; $y++)
{
    $row = mysql_fetch_array($participationResults);
    echo $row['activities_id'];
}//end for
}//end if[/code]

Now I want to use the results of this query into another query or manipulate it like, let's say if the query results are 2, 10 and 27. I'd like to be able to use only 2 or only 10 and so on.
I understand that the mysql_fetch_array returns the results in an array but can't figure out how to separate them.
My thought was to have them on an array to be able to use them. I'm open to any suggetions.

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/6605-query-results-to-an-array/
Share on other sites

Confused on what data are you wanting to use? The values from each column?
[code]
ID | ACT | VAR
2   | 10   |  27
[/code]

Is that the 2,10,27 you mean? Or
[code]
ID   | ACT | VAR
      |   2    |
      |   10  |
      |   27  |
[/code]
To use the 2nd way youll need a
[code]while ($row = mysql_fetch_array($partresults)) {
echo $row['activity_id'];
}[/code]
[!--quoteo(post=361743:date=Apr 4 2006, 05:44 PM:name=DrDre)--][div class=\'quotetop\']QUOTE(DrDre @ Apr 4 2006, 05:44 PM) [snapback]361743[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Confused on what data are you wanting to use? The values from each column?
[code]
ID | ACT | VAR
2   | 10   |  27
[/code]

Is that the 2,10,27 you mean? Or
[code]
ID   | ACT | VAR
      |   2    |
      |   10  |
      |   27  |
[/code]
To use the 2nd way youll need a
[code]while ($row = mysql_fetch_array($partresults)) {
echo $row['activity_id'];
}[/code]
[/quote]

The values 2, 10 and 27 are different rows under the activities_id column. This is the column I need to use on a different query.

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.