PDA

View Full Version : need help with a join


edgarperez
02-21-2005, 05:46 PM
I have two tables.
one has a list of drivers from 2004 and the second for 2005

I want to display a list of drivers that are in the 2004 list but no in the 2005 list. In other works, who participated in 2004 that is not partcipating in 2005.

I am trying to use a join of the two tables where a number in 2004 is not in the 2005 table.

code is this

$sqlquery = mysql_query("SELECT * FROM 2004_points a where a.race_number not in (select b.race_number from 2005_points b)" ,$db);



echo ("<table border ='0' align='center' class='main'cellpadding='2' cellspacing='0'>" );
echo ("<tr align='center' valign='bottom' class='sideboxexleftalign'>
<th><a href='2005drivers.php?columnName=race_number'>No.</a>
<th><a href='2005drivers.php?columnName=first_name'>First Name</a>
<th><a href='2005drivers.php?columnName=last_name'>Last Name</a>
<th><a href='2005drivers.php?columnName=hometown'>City</a>
<th><a href='2005drivers.php?columnName=state'>State</a>
<th><a href='2005drivers.php?columnName=year'>Year</a>
<th><a href='2005drivers.php?columnName=club'>Club</a>
<th><a href='2005drivers.php?columnName=total&SortOrder=DESC'>Points</a></tr>");
while ($tablerows = mysql_fetch_row($sqlquery))
{
echo("<tr valign='middle' ONMOUSEOVER=this.bgColor='#000000'; ONMOUSEOUT=this.bgColor='#333333';>
<td valign='top'>$tablerows[0]</td>
<td valign='top'>a.$tablerows[1]</td>
<td valign='top'>a.$tablerows[2]a.$tablerows[8]</td>
<td valign='top'>a.$tablerows[3]</td>
<td valign='top' class='sideboxes'>a.$tablerows[6]</td>
<td valign='top' class='sideboxes'>a.$tablerows[4]</td>
<td valign='top' class='sideboxes'>a.$tablerows[5]</td>
<td valign='top' class='sideboxes'>a.$tablerows[20]</td>");
}


My error is this
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/corvett1/public_html/2005driversnotsigned.php on line 36


Line 36 contains
while ($tablerows = mysql_fetch_row($sqlquery))

Mr. Popularity
02-22-2005, 03:41 AM
can you be more specific as to what you want to do? There may be an easier way than table joins.... believe me.. table joins can be a pain in the @$$.

:)

edgarperez
02-22-2005, 12:33 PM
Example.

I have a table for points earned by drivers in 2004
Say you and I are in that table.

I created a new table for drivers in 2005.
Say you moved and are no longer a driver in 2005 so only I am in the 2005 table.

I need a list that tells me you are not in the 2005 table. So I need to compare the names (numbers) in 2005 to 2004 and provide all that exist in 2004 but NOT 2005.

I will use this list to try and figure out why drivers who raced in 2004 are not racing in 2005.

Silmaril8n
02-22-2005, 12:39 PM
Not that it helps much but those errors are very generic. They are basically telling you that you have a bad query that there is nothing in that resultset. This of course, you already knew. Like Mr. Popularity said though, give us some more details and someone will be able to help.