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! Quote Link to comment 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'; Quote Link to comment Share on other sites More sharing options...
newbie_07 Posted May 19, 2008 Author Share Posted May 19, 2008 Still not working... Quote Link to comment 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"; Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 use mysql_num_rows() then echo it Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
beboo002 Posted May 19, 2008 Share Posted May 19, 2008 plz paste ur full query Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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> <? } ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 19, 2008 Share Posted May 19, 2008 You never set $tot_price. =/ Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.