Jump to content

What's the best way to do this ? MySQL db


sws

Recommended Posts

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 66

Could it be because I'm using $table_row while trying to select from 2 different tables ?

Link to comment
Share on other sites

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
Share on other sites

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 manager

return example might be...

[code]manager    total (points)
Manager One 26
Manager Two 23
Manager Three 20
Manager Four 17[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.