Jump to content

displaying multiple array results using myrow with 1 query


CBR

Recommended Posts

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?

 

Link to comment
Share on other sites

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>




Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

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.