Jump to content

What's the best way to handle this ? My SQL 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 ?
You should always check if a query worked before trying to fetch. You have an error at the query. Display it to help solve your problem. For instance, if the points column exists in both tables, then MySQL won't know which one to use (since you didn't specify a "a." or "b.").

$standings_query = mysql_query($standings_sql);
if (!$standings_query) {
  echo 'SQL error: ', mysql_error();
  exit; // error handling
}
while ($table_row = mysql_fetch_array($standings_query)) { ... }
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 ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.