I am running a PHP update code to update prices in a catalogue.
The import table has 5862 records. The catalogue table is empty.
When I execute the following code (with the mysql_query($insert) commented out)
My $new variable reads 5862 at the end of the code completion.
However, if I un-comment and execute the code again I get a random number of new records in my catalogue table and my last 2 lines of code never execute.
I suspect that something in the import table is possibly corrupting the code and it is crashing but I cannot find any suspect items.
Any suggestions please
Thanks
JemQ
$new = 0;
$updated = 0;
// assign the query
$query = "SELECT * FROM import_allpet LIMIT 9999";
// Execute the query
$result = mysql_query( $query );
if (!$result){
die ("Could not query the database: <br />". mysql_error( ));
}
// Setup the Table
echo "<table width='0' border='1' cellpadding='1'>";
echo "<tr>";
echo "<th scope='col'>TWB Code</th>";
echo "<th scope='col'>Allpet Code</th>";
echo "<th scope='col'>Description</th>";
echo "<th scope='col'>Cost Ex $</th>";
echo "<th scope='col'>Updated</th>";
echo "<th scope='col'>Updated/New Count</th>";
echo "</tr>";
// Fetch and display the results
while ($result_row = mysql_fetch_row(($result))){
$query2 = "SELECT * FROM allpet_twb WHERE allpetcode='{$result_row[1]}'";
$result2= mysql_query( $query2 );
$numrows = mysql_num_rows($result2);
if ( $numrows > 0) {
//if (costex == '{$result_row[3]}'){
$update= "UPDATE allpet_twb SET '{costex}'='{$result_row[3]}, status =
'Updated' WHERE '{allpetcode}'='{$result_row[1]}'";
//mysql_query($update);
$updated = $updated + 1;
echo"<tr>";
echo"<td> $result_row[4]</td>";
echo"<td> $result_row[1]</td>";
echo"<td> $result_row[2]</td>";
echo"<td align='right'>$ $result_row[3]</td>";
echo"<td>UPDATE</td>";
echo"<td>$updated / $new</td>";
echo"</tr>";
//}
}
else{
$insert="INSERT INTO allpet_twb (allpetcode,description,costex,status) VALUES
('{$result_row[1]}','{$result_row[2]}','{$result_row[3]}','NEW') ";
[COLOR="Red"]//mysql_query($insert);[/COLOR]
$new = $new + 1;
echo"<tr>";
echo"<td> $result_row[4]</td>";
echo"<td> $result_row[1]</td>";
echo"<td> $result_row[2]</td>";
echo"<td align='right'>$ $result_row[3]</td>";
echo"<td>NEW</td>";
echo"<td>$updated / $new</td>";
echo"</tr>";
}
}
echo "Records Updated = $updated <br>";
echo "New Records = $new <br>";