Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-10-2009, 01:53 PM Mysql Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
PHP Code:
$matches mysql_query("SELECT * FROM `manager__******` WHERE `home_team` = '16' OR `away_team` = '16' AND `season` = '7' ORDER BY `day` ASC LIMIT 1"); 
Whenever i run this query on the database i receive results that i shouldnt.

I shouldn't receive any results at all because both results in the database have a season value of 6. But for some reason it pulls the result where `home_team` = 16.

Database:

home_team away_team season
Row 1: 16 20 6
Row 2: 20 16 6

Results Using Query

Row1: 16 20 6

Last edited by evans123; 12-10-2009 at 02:00 PM..
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 12-10-2009, 02:29 PM Re: Mysql Results
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
'16' is a STRING value that will not be equal to the numeric value of 16
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-10-2009, 03:54 PM Re: Mysql Results
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Try adding paranthesis (don't know how to spell that :P) around the two home team compares.

SELECT * FROM table WHERE (team1 = 16 OR team2 = 16) AND season = 6

In your case, without the (), MySQL runs this query

SELECT * FROM table WHERE team1 = 16 OR (team2 = 16 AND season = 6)
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-10-2009, 04:10 PM Re: Mysql Results
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Kudos to Mattias, I was going to point that.
I even got burned by that very case today (duh...)

Chris, in those cases, mysql does an implicit cast from varchar to int, so it should not be a problem.
Just unnecessary work by the server.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-11-2009, 01:24 AM Re: Mysql Results
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
cheers guys i tried using " necause the variables are selected using a $_SESSION but this didnt work, as soon it went into brackets ( ) it worked.
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 12-11-2009, 04:30 AM Re: Mysql Results
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by tripy View Post
Kudos to Mattias,
Absolutely.

Quote:
Originally Posted by tripy View Post
Chris, in those cases, mysql does an implicit cast from varchar to int, so it should not be a problem.
Just unnecessary work by the server.
True,

Although I have had occasional "issues" with this so I prefer not to rely on the casting.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Mysql Results
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17391 seconds with 12 queries