Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-19-2008, 02:50 AM   #1 (permalink)
sudhakararaog
Junior Member
 
Join Date: Jan 2008
Posts: 1
Default question about select query

there is a report which displays the enquiries made by users in the below mentioned format.
the count column refers to how many number of times an enquiry was made for a particular city

count city price

2 sydney $100
1 perth $200
2 melbourne $300

the total value of the enquiries should be $1000 ( 2 X $100 + 1 X $200 + 2 X $300) presently i am able to add the price column which displays $600 actually it should be $1000

following is the code presently

================================================== ============================

mysql_select_db($database_connEnquiry, $connEnquiry);

$sql = " SELECT Count(*) as Counts, Title, City, Price, FROM `enquiry` WHERE date_format(en_date,'%Y-%m-%d') BETWEEN '" . $startDate . "' AND '" . $endDate . "' " . "
Group By Title, City, Price Order By Counts Desc, Title Desc, mode, Price";

$rs_newEnquiries = mysql_query($sql, $connEnquiry) or die(dbError(query1));

$echoStr = "<table width='80%' cellpadding=1 cellspacing=1 border=0><tr bgcolor='#cccccc;'><th bgcolor='#cccccc'
width=10>Count</th><th bgcolor='#cccccc' width=400>Destination</th><th bgcolor='#cccccc' width=100>Direct
Enquiries</th><th bgcolor='#cccccc' width=100>Mode</th> <th bgcolor='#cccccc' width=50>Priced From</th>
<th bgcolor='#cccccc' width=35>numAdults</th> <th bgcolor='#cccccc' width=35>numChildren</th> <th bgcolor='#cccccc' width=30>numInfants</th> <th align='center'

bgcolor='#cccccc'>Story</th> </tr>";

$total = 0; $totalprice = 0;

while ($row_rs_newEnquiries = mysql_fetch_assoc($rs_newEnquiries))
{
$echoStr .= "
<tr bgcolor='#ebebeb' class='default'><td>".$row_rs_newEnquiries['Counts']."</td>
<td class='default'>&nbsp; ".$row_rs_newEnquiries['Title']."</td>
<td class='default'>&nbsp; ".$row_rs_newEnquiries['City']."</td>
<td class='default'>&nbsp; ".$row_rs_newEnquiries['Price']."</td>
</tr>";
$total = $total + $row_rs_newEnquiries['Counts'];

$totalprice = $totalprice + $row_rs_newEnquiries['Price'];
}

$echoStr .= "<tr bgcolor='#cccccc;'><th align=\"left\" bgcolor='#cccccc'><b>".$total."</b></th>
<th bgcolor='#cccccc'>Total</th>

<td bgcolor='#cccccc'>&nbsp;</td><td bgcolor='#cccccc'></td><td bgcolor='#cccccc'><b>$&nbsp;".$totalprice."</b> </td><td bgcolor='#cccccc'><b>".$totalnumadults."</b></td><td

bgcolor='#cccccc'><b>".$totalnumchildren."</b></td><td bgcolor='#cccccc'><b>".$totalnuminfants."</b></td><td bgcolor='#cccccc'></td></tr></table>";

================================================== ============================

With the above code i am able to add the value of the price and display the $ amount. however if the count for a city is for example 2 which means there were 2 enquiries for

example city sydney and the price is $100 then the total should be 2 X $100 which is $200 how can i change the above above code in a way that the $totalprice will be able to
1) multiply the numeric value in count column with the price column and similarly for all the rows
2) and add the $ amount in the price column and sum it up and be able to display in echo $totalprice;

please advice.

thanks
sudhakararaog is offline   Reply With Quote
Sponsored Links
Old 02-04-2008, 03:57 AM   #2 (permalink)
lingsharma
Junior Member
 
Join Date: Feb 2008
Posts: 7
Default Re: question about select query

Pls post the output you are getting now in the form of image so that i can understand your question better. Then i'll help you with the code.
lingsharma is offline   Reply With Quote
Old 03-22-2008, 10:55 PM   #3 (permalink)
etono
Moderator
 
Join Date: May 2006
Posts: 86
Default Re: question about select query

Hello Sudhakararaog,

Sorry for the late reply. Here is what you currently have for totaling up the amount:

$totalprice = $totalprice + $row_rs_newEnquiries['Price'];

But, I think you should be multiplying the price time the count like this:

$totalprice = $totalprice + ($row_rs_newEnquiries['Price'] * $row_rs_newEnquiries['Counts']);
__________________
Jeremy Moseley
My Links: Design Related Blog | Personal Website | Portfolio
etono is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 12:12 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums