Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>$select_agent_id = mysql_query("select agent_id from bill group by agent_id"); while ($fetch = mysql_fetch_array($select_agent_id)) { $agent_id[] = $fetch['agent_id']; } $number_of_agents = count($agent_id); $output = "&lt;table border='2px' bordercolor='#460000'&gt;"; $output .="&lt;tr&gt;"; $output .="&lt;td&gt;Name&lt;/td&gt;"; for($i=1; $i&lt;=31; $i++) { $output .="&lt;td&gt;".$i."&lt;/td&gt;"; } $output .="&lt;td&gt;Total&lt;/td&gt;"; $output .="&lt;/tr&gt;"; foreach($agent_id as $id) { $select_records = mysql_query("select *, sum(amount) from bill where agent_id = $id and date between '2013-01-01' and '2013-01-31' group by date"); $select_agent_name = mysql_query("select name from bill_agents where id=$id"); $fetch_name = mysql_fetch_array($select_agent_name); $agent_name = $fetch_name['name']; $rows_count = mysql_num_rows($select_records); while($fetch_dates = mysql_fetch_array($select_records)) { $dates[] =substr($fetch_dates['date'],-2,2); $amounts[] = $fetch_dates['sum(amount)']; } $output .= "&lt;tr&gt;"; $output .="&lt;td&gt;".$agent_name."&lt;/td&gt;"; for($i=1;$i&lt;=31;$i++) { if(!empty($dates)) { if($i==$dates[0]) { $output .="&lt;td&gt;".$amounts[0]."&lt;/td&gt;"; array_shift($amounts); array_shift($dates); } else { $output .= "&lt;td&gt;&amp;nbsp;&lt;/td&gt;"; } } else { $output .= "&lt;td&gt;&amp;nbsp;&lt;/td&gt;"; } } $total_amount_query = mysql_query("select sum(amount) from bill where agent_id = $id and date between '2013-01-01' and '2013-01-31' group by agent_id"); $fetch_total_amount = mysql_fetch_array($total_amount_query); $output .="&lt;td&gt;".$fetch_total_amount['sum(amount)']."&lt;/td&gt;"; $output .= "&lt;/tr&gt;"; } $output .="&lt;/table&gt;"; echo $output; </code></pre> <p>@Preethu Alex : Above is you code. Please check and let me know. Hope this helps. I have not done any checking for <strong>SQL INJECTION</strong>. I have also given some dates as static in the query. Please modify it accodingly</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload