cleibesouza Posted April 4, 2006 Share Posted April 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6605-query-results-to-an-array/ Share on other sites More sharing options...
DrDre Posted April 4, 2006 Share Posted April 4, 2006 Confused on what data are you wanting to use? The values from each column?[code]ID | ACT | VAR2 | 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 Link to comment https://forums.phpfreaks.com/topic/6605-query-results-to-an-array/#findComment-23990 Share on other sites More sharing options...
cleibesouza Posted April 4, 2006 Author Share Posted April 4, 2006 [!--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 | VAR2 | 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. Quote Link to comment https://forums.phpfreaks.com/topic/6605-query-results-to-an-array/#findComment-23992 Share on other sites More sharing options...
DrDre Posted April 4, 2006 Share Posted April 4, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/6605-query-results-to-an-array/#findComment-23996 Share on other sites More sharing options...
cleibesouza Posted April 4, 2006 Author Share Posted April 4, 2006 Getting this warning now:Warning: Cannot use a scalar value as an array in [filepath] on line [line #] Quote Link to comment https://forums.phpfreaks.com/topic/6605-query-results-to-an-array/#findComment-24000 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.