Page 1 of 1
Required Help in MYSQL Query.............
Posted: Sat Jan 09, 2010 2:37 am
by manojsemwal1
iam using the following the query ....
SELECT district,block, SUM( IF( Approval = 'D', 1, 0 ) ) AS `Direct` , SUM( IF( Approval = 'C', 1, 0 ) ) AS `Complete` , SUM( IF( Approval = 'A', 1, 0 ) ) AS 'Approved' FROM studentregdtb GROUP BY block, District"
in query result is district iterate n times , i want to print the district only once time when the district value change it print and again break.

- query.JPG (17.83 KiB) Viewed 577 times
see the image
how we can do it in php.
Re: Required Help in MYSQL Query.............
Posted: Sat Jan 09, 2010 4:35 am
by jayshields
You'll just need to use PHP to help you with your formatting.
For example, loop through the query, storing the district each time, if the district is different from the last one, break and print it - if it's not different from the last one just print the row without the district.
Re: Required Help in MYSQL Query.............
Posted: Sat Jan 09, 2010 4:45 am
by manojsemwal1
Thanks for your reply .....
i tried in php but its not print properly coding are
while($row = mysql_fetch_array($sql))
{
// print_r($row);
echo"<tr ><td class='x-blue_dg_td dg_center dg_nowrap' > $row[district]</td>";
<td class='x-blue_dg_td dg_center dg_nowrap' >$row[block]</td>
<td class='x-blue_dg_td dg_center dg_nowrap' >$row[Direct]</td>
<td class='x-blue_dg_td dg_center dg_nowrap' >$row[Complete]</td>
<td class='x-blue_dg_td dg_center dg_nowrap' >$row[Approved]</td>";
}
Re: Required Help in MYSQL Query.............
Posted: Sat Jan 09, 2010 9:01 am
by SimpleManWeb
Try something like this:
Code: Select all
$LastDistrict = "";
while($row = mysql_fetch_array($sql)) {
if ($row['district] != $LastDistrict) {
?>
<tr ><td class='x-blue_dg_td dg_center dg_nowrap' colspan="4" > $row[district]</td>
<?php
$LastDistrict = $row['district'];
}
?>
<tr>
<td class='x-blue_dg_td dg_center dg_nowrap' ><?php echo $row[block]; ?></td>
<td class='x-blue_dg_td dg_center dg_nowrap' ><?php echo $row[Direct]; ?></td>
<td class='x-blue_dg_td dg_center dg_nowrap' ><?php echo $row[Complete]; ?></td>
<td class='x-blue_dg_td dg_center dg_nowrap' ><?php echo $row[Approved]; ?></td>
</tr>
}
I didn't test that code, but it should work.
Hope this helps
Re: Required Help in MYSQL Query.............
Posted: Mon Jan 11, 2010 1:44 am
by manojsemwal1
Thanks Dude its work fine...................
i appreciate your work........be in touch.........
Thanks