I'm using $.post for posting some data, for eg, a variable, company name to a controller method, inside a php foreach loop. In the controller I echo back a bargraph that is plotted using the data that is passed. Now inside the foreach loop I'm dynamically generating an id which will be passed to a certain '' element and I need to plot this bargraph passed back inside that div. The code I'm using now is posted below:
<?php
$id=0;
foreach($customer_companies as $data) {
$company_name=$data->CompanyName;
echo '<tr>
<script>function show_graph()
{
$.post("'.$base.'reports/single_bargraph/'.$company_name.'", {},function(result){
$("#'.$id.'").html(result);
});
}
</script>
<td class="tablecntntgry" id="'.$id.'" height="45">
<script type="text/javascript"> show_graph(); </script>
</td>
</tr>';
?>
Suppose, I have implemented pagination for fetching data $customer_companies, and 3 are displayed in page at a time. Now the problem that I face is the graph is not plotted in the id's specified.:( Sometimes, it would be plotted in the correct 3 td's generated but sometimes 2/3 would be plotted in the same td overlapping the other:( Can someone help me with this?