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 02-16-2008, 04:08 AM Mysql Select
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
I have a database of 20 teams i would like to select 10 fixtures from my database where the home_team is not equal to the away_team and the away_team is not equal to the home_team in other words each team plays once.

can i do this? because it doesnt seem to be working!

PHP Code:
mysql_query("SELECT * FROM `manager__fixtures` WHERE `league` = '$league_id' && `home_team` != `away_team` && `away_team` != `home_team`"); 
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
 
Register now for full access!
Old 02-16-2008, 12:43 PM Re: Mysql Select
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Are you sure manager__fixtures should have 2 underscores?

Also, if away_team != home_team then the reverse is true and you don't need to say it.

I don't know sports and you didn't bother to share your database structure, so I'm not sure about this, but I think you'll need to consider joining the table with itself to cross reference the teams.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-16-2008, 02:15 PM Re: Mysql Select
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
ye it shud have two _ as it groups them in the database under the main title manager.

DB Structure


id bigint(225) auto_increment
home_team int(225)
away_team int(225)
date varchar(225)
type varchar(225)
league int(225)
match_day int(225)
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-17-2008, 12:39 AM Re: Mysql Select
ry60003333's Avatar
Novice Talker

Posts: 5
Name: Ryan
Trades: 0
The query looks right. Are the ones with $ variables? Because in single quotes variable values aren't put in, the text it taken literally.
ry60003333 is offline
Reply With Quote
View Public Profile Visit ry60003333's homepage!
 
Old 02-17-2008, 04:06 AM Re: Mysql Select
evans123's Avatar
Ultra Talker

Posts: 468
Trades: 0
yep ' single quote for variables and ` for field names!
evans123 is offline
Reply With Quote
View Public Profile Visit evans123's homepage!
 
Old 02-17-2008, 11:54 PM Re: Mysql Select
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Sounds like you'll need a join. Here's an example with an INNER JOIN that may guide you on the right path:

PHP Code:
mysql_query("SELECT * FROM manager__fixtures home_table,manager__fixtures away_table WHERE home_table.league = '$league_id' && home_table.home_team != away_table.away_team"); 
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Mysql Select
 

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.39860 seconds with 12 queries