Jump to content

Archived

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

cleibesouza

Query results to an array

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.

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Getting this warning now:
Warning: Cannot use a scalar value as an array in [filepath] on line [line #]

Share this post


Link to post
Share on other sites

×

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.