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.
see the image
how we can do it in php.
Required Help in MYSQL Query.............
Moderator: General Moderators
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Required Help in MYSQL Query.............
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.
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.
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: Required Help in MYSQL Query.............
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>";
}
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>";
}
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: Required Help in MYSQL Query.............
Try something like this:
I didn't test that code, but it should work.
Hope this helps
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>
}
Hope this helps
-
manojsemwal1
- Forum Contributor
- Posts: 217
- Joined: Mon Jun 29, 2009 4:13 am
- Location: India
Re: Required Help in MYSQL Query.............
Thanks Dude its work fine...................
i appreciate your work........be in touch.........
Thanks
i appreciate your work........be in touch.........
Thanks