...

View Full Version : MySQL Query PHP Problems



dniwebdesign
06-22-2004, 05:26 AM
How come this doesn't want to work:


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='".$team."' AND visitingteam='".$team."' ORDER BY gamenumber");


However this does?


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='".$team."' ORDER BY gamenumber");

faxm0dem
06-22-2004, 08:09 AM
How come this doesn't want to work:


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='".$team."' AND visitingteam='".$team."' ORDER BY gamenumber");


However this does?


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='".$team."' ORDER BY gamenumber");

what do you mean by "doesn't want to work" ??
is there a parse error? a mysql error?? or ist the result of the query empty (which is most likely the case) ??

please always post the exact error message tnx

Y-STU-K
06-22-2004, 09:28 AM
you do realise you don't need to concatenate a string when you are using double quotes don't you?


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='$team' ORDER BY gamenumber");

The SQL is fine though its in the correct places all i think is that your selecting an incorrect column

raf
06-22-2004, 12:42 PM
How come this doesn't want to work:


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='".$team."' AND visitingteam='".$team."' ORDER BY gamenumber");


However this does?


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='".$team."' ORDER BY gamenumber");
Must be quite a funny game, where both the home and the visitingteam are the same. So there are probably no records where these are the same.

dniwebdesign
06-22-2004, 07:04 PM
Well raf, once again you come back with your smart alleck remarks... thanks.


instead of AND I belive I should be using OR... thanks again.

raf
06-22-2004, 09:41 PM
You're welcome :thumbsup:

dniwebdesign
06-23-2004, 12:36 AM
Well, sorry to bother you but this query


$result = mysql_query("SELECT * FROM hockeystats_schedule WHERE hometeam='$teams' OR visitingteam='$teams' ORDER BY gamenumber");

only returns the one game where the hometeam is right. I have two rows one game has the home team as Capitals and one the visiting the Capitals. It just returns the homegame and not the visiting games. Why?

raf
06-23-2004, 12:42 AM
1. Make sure that you are absolutely sure that there are other records with that value in one of the 2 columns;
2. Run the query directly inside a db-front like phpmyadmin or so and check the returned rows
3. Check your recordsetprocessing : do you have a correct loop to proces all rows?

dniwebdesign
06-23-2004, 01:14 AM
nm, I think i might have found the problem



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum