Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-24-2012, 08:51 PM   PM User | #1
fus10n
New Coder

 
Join Date: Oct 2010
Posts: 37
Thanks: 3
Thanked 0 Times in 0 Posts
fus10n is an unknown quantity at this point
Grrr sql rage

Okay, so the first portion of the code works where it deletes all rows where used = 1 however the else statement where if there are no rows where used = 1 doesn't work...any ideas???????


PHP Code:
<?php
$con 
mysql_connect("**","**","**");
mysql_select_db("**");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_query("DELETE FROM urls WHERE used='1'") or die(mysql_error());  

if (
mysql_affected_rows())
  {
  
//Rows were deleted
  
}
  else
  {
  
//No rows deleted so do some deleting
  
mysql_query("DELETE FROM urls ORDER BY id asc LIMIT 10") or die(mysql_error()); 
  }
?>
fus10n is offline   Reply With Quote
Old 04-24-2012, 09:30 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Works fine this end. I ran your code (using a different table name) to empty out my log_archive table:

PHP Code:
mysql_query("DELETE FROM log_archive WHERE id>'50'") or die(mysql_error());  

if (
mysql_affected_rows())
  {
  
//Rows were deleted
   
print 'deleted';
  }
  else
  {
  
//No rows deleted so do some deleting
  
mysql_query("DELETE FROM log_archive ORDER BY id asc LIMIT 10") or die(mysql_error()); 
   print 
'not deleted';
  } 
Took me 5 button clicks to delete the final 50 items so I can only say that your code works.

Are you sure you're on the right server? (Easy to run on one and then look at the database on another - eg localhost and the remote server).
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:04 AM.


Advertisement
Log in to turn off these ads.