Jump to content

Comparing results from two tables


djiles

Recommended Posts

I am having some major trouble comparing information from 2 tables. I am attempting to verify the information in similar columns, so that I can come up with a number.  The columns are setup as varchar(30).

 

The basic idea of the program is to obtain the Qualifying results for a race, and then add them to the table with Race results. Any help would be great.

 

Thanks

 

 

Trouble code

 

$result1 = mysql_query("SELECT * FROM QT WHERE DATE = '2007-08-28' ORDER BY Min, Sec, Hun"); 

echo '<tr>';
echo '<td>';
echo $Posr;
echo '</td>';



while ($row1 = @mysql_fetch_row($result1)){

$GT1 = $row["GT"];
$GT2 = $row1["GT"];

IF ($GT1 != $GT2){
	$Store + 1;
}
ELSE IF ($GT1 == $GT2){
	$SPos = ($Store + 1);
}
}

 

Added to working code.

 

//Query that is being run

$result = mysql_query("SELECT * FROM Race WHERE Date = '2007-08-28' ORDER BY THou, TMin, TSec, THun"); 

//this is a line break before the spit output

echo '<table border="1">';
echo '<tr>';
echo '<th>Fn</th>';
echo '<th>St</th>';
echo '<th>Driver</th>';
echo '<th>Car</th>';
echo '<th>Points</th>';
echo '<th>Purse</th>';
echo '<th>Laps</th>';
echo '<th>Race Time</th>';
echo '<th>Fastest Lap</th>';
echo '</tr>';

$Points = 35;
$Posr = 1;
$Purse = 15000;
$SPos = 0;
$Store = 0;

while ($row = @mysql_fetch_array($result))
{
if ($Points > 20)
{

//Query2 that is being run

$result1 = mysql_query("SELECT * FROM QT WHERE DATE = '2007-08-28' ORDER BY Min, Sec, Hun"); 

echo '<tr>';
echo '<td>';
echo $Posr;
echo '</td>';



while ($row1 = @mysql_fetch_row($result1)){

$GT1 = $row["GT"];
$GT2 = $row1["GT"];

IF ($GT1 != $GT2){
	$Store + 1;
}
ELSE IF ($GT1 == $GT2){
	$SPos = ($Store + 1);
}
}

echo '<td>';
echo $SPos;
echo '</td>';
echo '<td>'.$row["GT"].'</td>';
echo '<td>#'.$row["Car"].'</td>';
echo '<td>';
echo $Points;
echo '</td>';
echo '<td>';
echo $Purse;
echo '</td>';
echo '<td>'.$row["Laps"].'</td>';
echo '<td>'.$row["THou"].':'.$row["TMin"].':'.$row["TSec"].'.'.$row["THun"].'</td>';
echo '<td>'.$row["LMin"].':'.$row["LSec"].'.'.$row["LHun"].'</td>';
echo '</tr>';

$Points = ($Points - 3);
$Posr++;
$Purse = ($Purse - 250);
$SPos = 0;
}

 

Link to comment
https://forums.phpfreaks.com/topic/67092-comparing-results-from-two-tables/
Share on other sites

here is a link to the current php

 

http://www.onlinemotorsportsclub.com/league/test4.php

 

As you can see everything is there and can be pulled from Table Race, but I want the Qualifying position to show as ST.  But no matter what I do it either returns 0 or the full row count 19. 

 

The problem is I need to accumulate the row count from QT until it reaches the current GT return from Race. Does that make any since?  The idea behind this is to have two tables with the same column data to verify with.

 

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.