How can I speed up this query?
Posted: Tue Aug 22, 2006 1:35 pm
Hi All:
I have 1 table into which I load data on a daily basis, assinging the current date and an item code to the table and the primary index. (ie index PRIMARY date, itemcode).
I want to be able to compare the information I loaded today, for instance, with the information I loaded yesterday and generate a brief output of records that have changed. Below is a sample of the PHP code im using to achieve this. The thing is it works, but it is VERY SLOW. There are obviously better ways of doing this so can anyone point me in the right direction to speed it up a little?
I have 1 table into which I load data on a daily basis, assinging the current date and an item code to the table and the primary index. (ie index PRIMARY date, itemcode).
I want to be able to compare the information I loaded today, for instance, with the information I loaded yesterday and generate a brief output of records that have changed. Below is a sample of the PHP code im using to achieve this. The thing is it works, but it is VERY SLOW. There are obviously better ways of doing this so can anyone point me in the right direction to speed it up a little?
Code: Select all
<?
$query="select * from TABLE1 where daDate = '2006-08-22'";
$line=mysql_query($query)or die(mysql_error());
while($row=mysql_fetch_array($line)){
$query2="select * from TABLE1 where daDate = '2006-08-21' AND itemCode =".$row['itemCode'];
$line2=mysql_query($query2)or die(mysql_error());
while($row2=mysql_fetch_array($line2)){
if ($row['value'] <> $row2['value']) {
echo '<tr align = "center">'."\n";
echo "\t".'<td>'.$row2['Description'].'</td><td>'.$row2[value].$row[value].'</td>'."\n"; echo '</tr>'."\n";
}
}
}
?>