Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Grrr sql rage

  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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()); 
      }
    ?>

  2. #2
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,002
    Thanks
    104
    Thanked 586 Times in 573 Posts
    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).
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •