data is not displaying in foreach loop

Hi,

I am looping the data and displaying it from the database. But only one data set is displaying in the loop. I dont now where i am doing wrong. Here is my code. Please help me

$resultViewed = $this->model_report_product->getMostViewed(); $stringResult ="var data= google.visualization.arrayToDataTable([ ['Product', 'Views'],"; foreach($resultViewed as $results) { $stringResult = $stringResult . "['".$results['name']."',".$results['quantity']."],"; } $stringResult .= "]);"; $this->data['Viewed'] = $stringResult;

Where are you displaying the data. If you want to display the data for each entry you have to do it in the for each loop.

Well, you create a data set, $resultViewed.
Then, you create one output from it.
Then, you loop thru the data set.
Then, you display the output from the one and only output you created…

Hmmm… Do you see it now? You must loop thru the $resultViewed and each time, create output from it and then display that output. The output will never change if it is not INSIDE the loop…

Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service