newbie_07 Posted May 19, 2008 Share Posted May 19, 2008 Hi I am using the query for the grand total of the adjusted price. Here's my query and it returns nothing: $sql = "SELECT service_ordered, admin_comments, adj_price, sum(adj_price) as tot_price from services_ordered where services_ordered.client_id=$_POST[c_id] group by service_ordered"; Any idea! Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/ Share on other sites More sharing options...
oopster Posted May 19, 2008 Share Posted May 19, 2008 Hello It looks okey, but you should clean up your post value $sql = 'SELECT service_ordered, admin_comments, adj_price, sum(adj_price) as tot_price from services_ordered where services_ordered.client_id='.(int)$_POST['c_id'].' group by service_ordered'; Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544684 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 Still not working... Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544698 Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 ur query looks right first check your form field $_POST['c_id'] if you get value then try this query $sql = "SELECT service_ordered, admin_comments, adj_price, sum(adj_price) as tot_price from services_ordered where services_ordered.client_id='".$_POST['c_id']."' group by service_ordered"; Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544701 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 ur query looks right first check your form field $_POST['c_id'] if you get value then try this query $sql = "SELECT service_ordered, admin_comments, adj_price, sum(adj_price) as tot_price from services_ordered where services_ordered.client_id='".$_POST['c_id']."' group by service_ordered"; Again not working . I don't know whats the problem. When i test the query in mysql it works fine.... I have checked the $_post['c_id'] value is printing in the where clause. Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544703 Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 use mysql_num_rows() then echo it Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544706 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 use mysql_num_rows() then echo it It returns 2, means 2 records are present Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544708 Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 plz paste ur full query Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544711 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 please paste ur full query Ok $sql = "SELECT service_ordered, admin_comments, adj_price, sum(adj_price) as tot_price from services_ordered where services_ordered.client_id='".$_POST['c_id']."' group by service_ordered"; print "<br><br><br>".$sql ; $res = mysql_query($sql) or die(mysql_error()); $f = mysql_num_rows($res); echo "$f"; while($row=mysql_fetch_array($res)){ $s_names = $row['service_ordered']; $d_date = $row['']; $a_comments = $row['admin_comments']; $adj_price = $row['adj_price']; ?> <td><?php echo "$s_names"; ?></td> <td> </td> <td><?php echo "$a_comments"; ?></td> <td align="center"><?php echo "$adj_price"; ?></td> </tr> <?php } ?> <tr> <td colspan="3" class="trbg"><strong>Total Price: </strong></td> <td align="center"><?php echo "$tot_price"; ?></td> Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544715 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 Basically i am printing the adj_price one place as a single value in the column adjusted price and then printing it at another place as a total price. Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544718 Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 close while loop after this <td align="center"><?php echo "$tot_price"; ?></td> <? } ?> Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544719 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 close while loop after this <td align="center"><?php echo "$tot_price"; ?></td> <? } ?> Then it prints the Total Price td 2 times and still the value(tot_price) isn't printing. Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544723 Share on other sites More sharing options...
DarkWater Posted May 19, 2008 Share Posted May 19, 2008 You never set $tot_price. =/ Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544728 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 You never set $tot_price. =/ I am sorry, i couldn't get your point. Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544730 Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 Is there any alternate method where i can print the integer values of the field (adj_price) of the table as non-sum at one place and as a sum at the other place? Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544735 Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 Try this one $sql = "SELECT service_ordered, admin_comments, adj_price from services_ordered where services_ordered.client_id='".$_POST['c_id']."' group by service_ordered"; print "<br><br><br>".$sql ; res = mysql_query($sql) or die(mysql_error()); $f = mysql_num_rows($res); echo "$f"; while($row=mysql_fetch_array($res)){ $s_names = $row['service_ordered']; $d_date = $row['']; $a_comments = $row['admin_comments']; $adj_price = $row['adj_price']; $tot_price[]=$row['adj_price']; ?> <td><?php echo "$s_names"; ?></td> <td> </td> <td><?php echo "$a_comments"; ?></td> <td align="center"><?php echo "$adj_price"; ?></td> </tr> <?php } ?> <tr> <td colspan="3" class="trbg"><strong>Total Price: </strong></td> <td align="center"><?php echo array_sum($tot_price); ?></td> Link to comment https://forums.phpfreaks.com/topic/106283-grand-total-not-working/#findComment-544761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.