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
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]
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

[code]
$participationResults = mysql_query($participationQuery, $connection) or die (mysql_error());
$id=0;
while($row = mysql_fetch_array($participationResults)) {
    $results[$id] = $row['activities_id'];
    $id++;
}

[/code]

$results will be an array of all your results now
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.