There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell display driver drivers email error excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem ram router slow sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
question about select query using php


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
sudhakararaog's Avatar
Computer Specs
Member with 64 posts.
 
Join Date: Sep 2007
Experience: Intermediate
21-Jan-2008, 02:23 AM #1
question about select query using php
hi

i have an enquiry table which collects information about users
making an online travel enquiry

the fields in the table are = StoryTitle, EndCity, mode, PricedFrom,
numAdults, numChildren, numInfants

presently the select query is

<?php

$sql = SELECT Count(*) as Counts, StoryTitle, EndCity, mode,
PricedFrom, numAdults, numChildren, numInfants, ReturnLocation FROM
`enquiry` WHERE date_format(en_date,'%Y-%m-%d') BETWEEN '" .
$startDate . "' AND '" . $endDate . "' " . $enquiryText . "
Group By StoryTitle, EndCity, mode, PricedFrom, numAdults,
numChildren, numInfants, ReturnLocation
Order By Counts Desc, StoryTitle Desc, mode, PricedFrom, numAdults,
numChildren, numInfants, ReturnLocation";

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['StoryTitle']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['EndCity']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['mode']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['PricedFrom']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['numAdults']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['numChildren']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['numInfants']."</td>
<td class='default'>&nbsp; <a href=".$row_rs_newEnquiries
['ReturnLocation'].">".$row_rs_newEnquiries
['ReturnLocation']."</a></td>
</tr>";
$total = $total +
$row_rs_newEnquiries['Counts'];
}

$totalamount=$row_rs_newEnquiries['totalvalue'];

echo "value of total enquiry is $ ". $totalamount;

?>

i have used $totalamount=$row_rs_newEnquiries['totalvalue']; both
inside the while loop and outside the while loop however this is not
working.

here Counts is the column which collects the number of times an
enquiry was made to a particular city example Sydney however Counts
DOES NOT exist as a field in the table and PricedFrom collects the
value of the $ amount to a city and this field exists in the table,
so multiplying Counts and PricedFrom should give the result

is the syntax of the select query correct as there is a comma before
Count(*) & am i reading the value of this multiplied value correctly

please advice.

thanks.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
21-Jan-2008, 07:32 AM #2
lol, I really don't follow.
cristobal03's Avatar
Distinguished Member with 2,992 posts.
 
Join Date: Aug 2005
Experience: Advanced
21-Jan-2008, 07:03 PM #3
For one, your fetch is probably failing because you're using an undeclared variable (which I think in PHP initializes to an empty string). In other words, your SELECT query string is assigned to $sql, but you're fetching $rs_newEnquiries. I'm not going to even bother trying to figure out your database structure, but if you replace all instances of $rs_newEnquiries with $sql in the above code, at least your fetch should execute properly.

I imagine the technical answer to your question is that your fetch is returning an empty array, so when you try to assign $totalamount you're pointing to a null index. Also, if you cut and pasted that code, you're missing a double-quote at the beginning of your query string. I didn't really look for other mistakes.

chris.
Anthony:-P's Avatar
Computer Specs
Senior Member with 449 posts.
 
Join Date: Nov 2006
Location: UK
Experience: Between Intermediate and
22-Jan-2008, 04:39 AM #4
<?php

$sql = SELECT Count(*) as Counts, StoryTitle, EndCity, mode,
PricedFrom, numAdults, numChildren, numInfants, ReturnLocation FROM
`enquiry` WHERE date_format(en_date,'%Y-%m-%d') BETWEEN '" .
$startDate . "' AND '" . $endDate . "' " . $enquiryText . "
Group By StoryTitle, EndCity, mode, PricedFrom, numAdults,
numChildren, numInfants, ReturnLocation
Order By Counts Desc, StoryTitle Desc, mode, PricedFrom, numAdults,
numChildren, numInfants, ReturnLocation";

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['StoryTitle']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['EndCity']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['mode']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['PricedFrom']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['numAdults']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['numChildren']."</td>
<td
class='default'>&nbsp; ".$row_rs_newEnquiries['numInfants']."</td>
<td class='default'>&nbsp; <a href=".$row_rs_newEnquiries
['ReturnLocation'].">".$row_rs_newEnquiries
['ReturnLocation']."</a></td>
</tr>";
$total = $total +
$row_rs_newEnquiries['Counts'];
}

$totalamount=$row_rs_newEnquiries['totalvalue'];

echo "value of total enquiry is $ ". $totalamount;

?>

Hi,

You've also go $sql = SELECT, you've missed the " before SELECT.

I would be more inclined to do:

PHP Code:
$sql mysql_query("SELECT * FROM table_name WHERE column = 'value'");
while(
$row mysql_fetch_assoc($sql))
{
echo 
"then here you echo the rows ".$row['like_this'].", good luck!";

Also, as stated by cristobal above, you're not using your actual select query, you're using an empty string.

I'd also be inclined to initialise $totalamount before the loop, just to make sure.


Kind Regards,
Anthony
__________________
Currently training at geekstogo!
If your thread is solved, please mark as solved from the 'Thread Tools' menu.
My computer beat me at chess, however it was no match for me at kick boxing!
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:54 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.