CBR Posted January 29, 2010 Share Posted January 29, 2010 So I have this issue. I am calling a query and would like to display the result 3 times in 3 different ways. It is the same data in the 1 query I would like to display but in different orders. For instance. $result1= mysql_query("CALL noc_quality_report_sum('jbuhlman');") or die(mysql_error()); while ($myrow1 = mysql_fetch_array($result1)) { echo " <set value='".$myrow1["total_handled"]."' />";} } while ($myrow1 = mysql_fetch_array($result1)) { echo " <set value='".$myrow1["percent"]."' />";} } while ($myrow1 = mysql_fetch_array($result1)) { echo " <set value='".$myrow1["data1"]."' />";} } ... However this does not unless I run the query again before the while statements. IT is a performance problem executing the query 3 times instead of just once to get the same data. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/ Share on other sites More sharing options...
akitchin Posted January 29, 2010 Share Posted January 29, 2010 run through the query a single time, store the data into an array, and then use the array to re-display your data. Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003827 Share on other sites More sharing options...
CBR Posted January 29, 2010 Author Share Posted January 29, 2010 It isnt that simple. Each myrow could have hundreds of results. Maybe I am not understanding what you are saying. Take a look at my code. It is a bit more to it. <dataset seriesName='Total Alerts'> <?php //Call the proc() procedure $result1= mysql_query("CALL noc_quality_report_sum('jbuhlman');") or die(mysql_error()); mysql_close($con1); while ($myrow1 = mysql_fetch_array($result1)) { if ($myrow1['month1'] == '1' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '2' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '3' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '4' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '5' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '6' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '7' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '8' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '9' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '10' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '11' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '12' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} } ?> </dataset> <dataset color='FF0000' seriesName='Violations' renderAs='Area' parentYAxis='P'> <?php //Call the proc() procedure $result1= mysql_query("CALL noc_quality_report_sum('jbuhlman');") or die(mysql_error()); mysql_close($con1); while ($myrow1 = mysql_fetch_array($result1)) { if ($myrow1['month1'] == '1' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '2' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '3' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '4' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '5' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '6' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '7' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '8' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '9' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '10' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '11' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '12' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} } ?> </dataset> <dataset lineThickness='2' seriesName='Percent Handled' parentYAxis='S'> <?php //Call the proc() procedure $result1= mysql_query("CALL noc_quality_report_sum('jbuhlman');") or die(mysql_error()); mysql_close($con1); while ($myrow1 = mysql_fetch_array($result1)) { if ($myrow1['month1'] == '1' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '2' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '3' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '4' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '5' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '6' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '7' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '8' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '9' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '10' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '11' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '12' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} } ?> </dataset> <trendLines> <line startValue='90' color='00FF00' displayvalue='90% Target OLA' valueOnRight='1' parentYAxis='S'/> </trendLines> </chart> Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003829 Share on other sites More sharing options...
akitchin Posted January 29, 2010 Share Posted January 29, 2010 you should be able to store the resultset within an array regardless of how many records are in the set: $master_data_set = array(); while ($myrow1 = mysql_fetch_array($result1)) $master_data_set[] = $myrow1; then, when you need to go through the info, rather than running the query and using a while() loop, simply run a foreach() loop on $master_data_set. this saves you from having to query the database and have it return the same resultset. Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003830 Share on other sites More sharing options...
CBR Posted January 29, 2010 Author Share Posted January 29, 2010 Ill give that a whirl. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003831 Share on other sites More sharing options...
CBR Posted January 29, 2010 Author Share Posted January 29, 2010 the foreach usage is so poorly documented. Anyone have any examples of what I am trying to do above with usage of foreach? Not sure what the hell I am doing wrong. <dataset seriesName='Total Alerts'> <?php $con1 = mysql_connect(edited,false,65536); mysql_select_db('reporting'); //Call the proc() procedure $result1= mysql_query("CALL noc_quality_report_sum('jbuhlman');") or die(mysql_error()); mysql_close($con1); $master_data_set = array(); while ($myrow1 = mysql_fetch_array($result1)) $master_data_set[] = $myrow1; foreach($master_data_set) { if ($myrow1['month1'] == '1' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '2' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '3' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '4' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '5' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '6' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '7' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '8' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '9' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '10' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '11' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} elseif ($myrow1['month1'] == '12' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["total_handled"]."' />";} } ?> </dataset> <!--<dataset color='FF0000' seriesName='Violations' renderAs='Area' parentYAxis='P'>--> <dataset color='FF0000' seriesName='Violations' renderAs='Area' parentYAxis='P'> <?php foreach ($master_data_set) { if ($myrow1['month1'] == '1' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '2' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '3' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '4' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '5' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '6' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '7' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '8' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '9' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '10' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '11' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} elseif ($myrow1['month1'] == '12' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["violations"]."' />";} } ?> </dataset> <dataset lineThickness='2' seriesName='Percent Handled' parentYAxis='S'> <?php foreach ($master_data_set) { if ($myrow1['month1'] == '1' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '2' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '3' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '4' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '5' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '6' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '7' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '8' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '9' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '10' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '11' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} elseif ($myrow1['month1'] == '12' && $myrow1['year1'] == '2009'){ echo " <set value='".$myrow1["percent"]."' />";} } ?> </dataset> Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003911 Share on other sites More sharing options...
CBR Posted January 29, 2010 Author Share Posted January 29, 2010 FYI. I am willing to kick some money for help on this. I'm a bit confused on how this is accomplished. Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003925 Share on other sites More sharing options...
CBR Posted January 29, 2010 Author Share Posted January 29, 2010 Thanks for the PM help. Resolved. Quote Link to comment https://forums.phpfreaks.com/topic/190269-displaying-multiple-array-results-using-myrow-with-1-query/#findComment-1003937 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.