sws Posted November 12, 2006 Share Posted November 12, 2006 Hi,I've got a site where users can enter their hockey picks via a form. There are a series of drop down menus that allow them to select their roster. I have a players table that contain the stats for every nhl player.Now when the user submits their picks via the form it populates a managers table with their user id and the player id for every player they have selected.Now I'm trying to make a web page that displays the contest entrants and their points based on the user stats.What's the best way to handle that ?I tried this but am getting the following error:code: [code]<?php $standings_sql = "SELECT * FROM nhl_players a, nhl_managers b WHERE a.player_id = b.lwl OR a.player_id = b.lw2 ORDER BY points DESC";$standings_query = mysql_query($standings_sql);while ($table_row = mysql_fetch_array($standings_query)){ ?> <td colspan="2"><font face="Verdana, Times New Roman, Times, serif" size="-2" color="#990000"> <?=$table_row['handle']?> </font> </td><?}?>[/code]Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on Line 66Could it be because I'm using $table_row while trying to select from 2 different tables ? Link to comment https://forums.phpfreaks.com/topic/27029-whats-the-best-way-to-do-this-mysql-db/ Share on other sites More sharing options...
fenway Posted November 12, 2006 Share Posted November 12, 2006 See what mysql_error() says. Link to comment https://forums.phpfreaks.com/topic/27029-whats-the-best-way-to-do-this-mysql-db/#findComment-123593 Share on other sites More sharing options...
sws Posted November 12, 2006 Author Share Posted November 12, 2006 How do I do that ? Link to comment https://forums.phpfreaks.com/topic/27029-whats-the-best-way-to-do-this-mysql-db/#findComment-123596 Share on other sites More sharing options...
sws Posted November 12, 2006 Author Share Posted November 12, 2006 I've done some tweaking. Here's my new query that works.SELECT nhl_managers.handle, nhl_players.points FROM nhl_players, nhl_managers WHERE nhl_players.id = nhl_managers.lw1 OR nhl_players.id = nhl_managers.lw2 ORDER BY nhl_players.points DESC;This is working but it's returning one line for every player.What I need is to return the sum of all of the players points on one line with the nhl_managers.handle.Can someone please show me how to do this ? Link to comment https://forums.phpfreaks.com/topic/27029-whats-the-best-way-to-do-this-mysql-db/#findComment-123637 Share on other sites More sharing options...
printf Posted November 12, 2006 Share Posted November 12, 2006 Something like...[code]SELECT m.handle AS manager, SUM(p.points) AS total FROM nhl_managers AS m LEFT JOIN nhl_players AS p ON(m.lw1 = p.id OR m.lw2 = p.id) GROUP BY manager ORDER BY total DESC;[/code]That should return... (manager => $table_row['manager'], total => $table_row['total']), one row for each managerreturn example might be...[code]manager total (points)Manager One 26Manager Two 23Manager Three 20Manager Four 17[/code] Link to comment https://forums.phpfreaks.com/topic/27029-whats-the-best-way-to-do-this-mysql-db/#findComment-123659 Share on other sites More sharing options...
sws Posted November 13, 2006 Author Share Posted November 13, 2006 Awesome !! Thank you soooo much ! Link to comment https://forums.phpfreaks.com/topic/27029-whats-the-best-way-to-do-this-mysql-db/#findComment-123685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.