BigTime Posted December 23, 2012 Share Posted December 23, 2012 I have a form that needs to require certain parameters be set prior to showing it. I query one column to find the conditions in which it might be required the result set into an array if a currently set parameter is found within this array then check for second parameter being set if its set = show the form if its not set = offer choices to set so we can show the form My problem is in the damn while loop How can I take the data that comes out of the initial $results query and store them for use OUTSIDE a while loop? Thanks in adcance for any help # setup SQL statement $SQL = " SELECT DISTINCT column FROM table WHERE condition='$condition' AND condition2 != '' "; # execute SQL statement $result = mysql_db_query($db, $SQL, $cid); # check for errors if (!$result) { echo( mysql_error()); } $check = mysql_num_rows($result); #We have a split needed so print it if($check>'1') { while ($data=mysql_fetch_array($result)){ $columnresults=$data[column]; $columnarray = array($columnresults); #If our current division selected is in this array then show AND REQUIRE the split choice to show the form $this = $_GET['this']; if (in_array($this, $columnarray)) { if (!$that || $that=='') { echo (" THERE IS NO THAT WE NEED TO PROVIDE OPTIONS TO SET IT FIRST <BR>"); } elseif ($that || $that != '') { echo ("THAT IS SET SHOW THE FORM<BR>"); } } else (!in_array($this, $columnarray)){ echo ("I DONT NEED THAT I CAN JUST SHOW THE FORM<BR>"); } } } Quote Link to comment https://forums.phpfreaks.com/topic/272302-create-array-from-query-use-data-outside-while-loop/ Share on other sites More sharing options...
BigTime Posted December 23, 2012 Author Share Posted December 23, 2012 Or define new variables from array results? I dont need to loop my form 4 times I just want to know if what Im looking for is WITHIN the array in order to move to my next step If it is in the array - Check something else is set, YES show form, NO show choices If it is not in array - Show form The while loop makes it want to loop as many times as my results are - so 4 results, 4 loops. Im sure Im using the wrong method here. Hoping someone smart out there understands what Im trying to do Quote Link to comment https://forums.phpfreaks.com/topic/272302-create-array-from-query-use-data-outside-while-loop/#findComment-1400960 Share on other sites More sharing options...
kicken Posted December 23, 2012 Share Posted December 23, 2012 You can always just store your results into an array and then use them later, eg: $queryResults = array(); while ($data=mysql_fetch_assoc($results)){ $queryResults[] = $data; } //Now $queryResults holds all the rows/columns returned. If you just want the one column in an array by itself, then do that. $columnValues = array(); while ($data=mysql_fetch_assoc($results)){ $columnValues[] = $data['column']; } //Now $columnValues holds all the values from the specified column. Quote Link to comment https://forums.phpfreaks.com/topic/272302-create-array-from-query-use-data-outside-while-loop/#findComment-1400962 Share on other sites More sharing options...
BigTime Posted December 23, 2012 Author Share Posted December 23, 2012 Thank you so much kicken. Quote Link to comment https://forums.phpfreaks.com/topic/272302-create-array-from-query-use-data-outside-while-loop/#findComment-1400965 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.