MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 27th, 2004, 09:57 PM
delner delner is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 delner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > MySQL Update query not working


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT