johnny Posted August 11, 2006 Share Posted August 11, 2006 Ok I am beating my head against the wall trying to do this. Here are the tables I am working with:tablename = schedule __________________week | team | name1 | tm1 | A1 | tm2 | B2 | tm1 | C2 | tm2 | Btablename = points___________________name | 1 | 2 A | 4 | -2B | 0 | 3C | 2 | 1so I have a page where I want it to able to display the teams that play eachother (week1.tm1. vs week2.tms) as well as the player on each team AND how many pts they scored. so far I can get the teams and the players pretty easily, because they are in the same table. what i cannot figure out is how to code it to find that in Week 1, Team 1 had player A...then take that to the points page and pull the points that A scored in Week 1. I am currently trying this:[code]<?php $link = mysql_connect("xxx", "xxx", "xxx") or die("Could not connect : " . mysql_error());mysql_select_db("xxx") or die("Could not select database");$query="SELECT points.1FROM points.scheduleWHERE points.name= schedule.nameAND schedule.week = '1'AND schedule.team = 'tm1'";$res = mysql_query($query);while($row = mysql_fetch_assoc($res)){echo $row ['1'].'<br>';}?>[/code]I have also tried something like:[code]"SELECT 1FROM pointsWHERE name = (SELECT name FROM schedule WHERE week='1' AND team='tm1')"[/code]Both give me "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in line xx"I'll buy someone a keg to figure this out lol. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 11, 2006 Share Posted August 11, 2006 So, the column names in the points table are 'name', '1', and '2'? Quote Link to comment Share on other sites More sharing options...
johnny Posted August 11, 2006 Author Share Posted August 11, 2006 yes, 1 and 2 refer to week 1, week 2... Quote Link to comment Share on other sites More sharing options...
Barand Posted August 11, 2006 Share Posted August 11, 2006 I thought a colname comprising only numeric digits was illegal Quote Link to comment Share on other sites More sharing options...
johnny Posted August 11, 2006 Author Share Posted August 11, 2006 well that would be news to me and my database! lol i have gotten other queries to work on that table, just not the one i'm asking about. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 12, 2006 Share Posted August 12, 2006 Probably because the column names are not legal! Try changing them to 'one' and 'two', it's the only reason I can see why your query produces an error.When you've done that, you can do"select week, team, schedule.name, one, two from schedule, points where schedule.name=points.name"then you will get the all the teams with all the points scored by the player in the team for week one and week two, week by week. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 12, 2006 Share Posted August 12, 2006 Actually your first query should be[code]SELECT points.1FROM points, scheduleWHERE points.name= schedule.nameAND schedule.week = '1'AND schedule.team = 'tm1'[/code]Note the comma not full stop, between the table names. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 12, 2006 Share Posted August 12, 2006 So if column names are OK then to pull the first record from points table where the week 1 col has a value of 4 you would be using a query like"SELECT * FROM points WHERE 1 = 4" ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.