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
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,299
    Thanks
    57
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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).
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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