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. Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/ 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'? Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73337 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... Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73340 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 Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73351 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. Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73364 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. Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73449 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. Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73452 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" ??? Link to comment https://forums.phpfreaks.com/topic/17280-using-query-from-one-table-to-query-another-table-on-same-page/#findComment-73455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.