|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
MySQL Update query not working
I'm writing a PHP script that deletes a record out of a MySQL table then updates the ID's accordingly.
There is some problem with the MySQL query although when i put in print mysql_error(); nothing is returned. Here's a snippet of the code that is giving me trouble. Code:
$checkquery = "SELECT * FROM $mysqlnt";
$checkresult = mysql_query($checkquery);
while($checkrow = mysql_fetch_row($checkresult))
{
if($checkrow[4] > $id)
{
$newid = $checkrow[4] - 1;
$datequery = "SELECT date FROM $mysqlnt WHERE news_id = '$checkrow[4]'";
$postdate = mysql_query($datequery);
print "checkrow: $checkrow[4]<br>id: $id<br>newid: $newid<br><br>";
$cquery = "UPDATE $mysqlnt SET news_id = '$newid' WHERE date = \"$postdate\"";
mysql_query($cquery);
}
}
Here's what the table is configured like before the script is run... ------------------------------------- 'title','author','date','message','news_id' '5','delner','10:13:53 PM 7-27-04','5','5' '4','delner','10:13:51 PM 7-27-04','4','4' '3','delner','10:22:53 PM 7-27-04','3','3' '2','delner','10:13:45 PM 7-27-04','2','2' '1','delner','10:13:25 PM 7-27-04','1','1' ------------------------------------- This is what should happen when the script is told to delete record with ID #3 ------------------------------------- 'title','author','date','message','news_id' '5','delner','10:13:53 PM 7-27-04','5','4' '4','delner','10:13:51 PM 7-27-04','4','3' '2','delner','10:13:45 PM 7-27-04','2','2' '1','delner','10:13:25 PM 7-27-04','1','1' ------------------------------------- But this is what happens... ------------------------------------- 'title','author','date','message','news_id' '5','delner','10:13:53 PM 7-27-04','5','5' '4','delner','10:13:51 PM 7-27-04','4','4' '2','delner','10:13:45 PM 7-27-04','2','2' '1','delner','10:13:25 PM 7-27-04','1','1' ------------------------------------- Any clue on how to fix this? |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > MySQL Update query not working |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|