www.webdeveloper.com
Results 1 to 3 of 3

Thread: delete row after doing query

  1. #1
    Join Date
    Jun 2007
    Location
    England
    Posts
    448

    Exclamation delete row after doing query

    Hello, i have the below cronjob that looks at the database "buildup" and finds all the things that have finnished. then if they have finnished it +1 on the building it has.

    how can i delete each row after it has gone through each one of the database. so once it has done a row it deletes it, then the next then deletes it etc.

    PHP Code:
    <?php
    //Create Funcion: buildup_cron
    function buildup_cron() {

        
    $timeStamp time();
        
    $result mysql_query("SELECT * FROM buildup WHERE endtime<'$timeStamp'");
        
        while(
    $row mysql_fetch_array($result)) {

    if(
    $row['building'] == 1)
        
    $upgrade"bank";
    elseif(
    $row['building'] == 2)
        
    $upgrade"house";
    elseif(
    $row['building'] == 3)
        
    $upgrade"harbour";
    elseif(
    $row['building'] == 4)
        
    $upgrade"temple";
    else
        echo 
    "error, doh!";

    mysql_query("UPDATE users SET $upgrade=$upgrade+'1' WHERE id='$row[userid]'");
            
        }
        
    }

    //run cron
    buildup_cron();
    ?>
    thanks to anyone that helps me

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    just add a delete statement.

    PHP Code:
    <?php
    //Create Funcion: buildup_cron
    function buildup_cron() {

        
    $timeStamp time();
        
    $result mysql_query("SELECT * FROM buildup WHERE endtime<'$timeStamp'");
        
        while(
    $row mysql_fetch_array($result)) {

    if(
    $row['building'] == 1)
        
    $upgrade"bank";
    elseif(
    $row['building'] == 2)
        
    $upgrade"house";
    elseif(
    $row['building'] == 3)
        
    $upgrade"harbour";
    elseif(
    $row['building'] == 4)
        
    $upgrade"temple";
    else
        echo 
    "error, doh!";

    mysql_query("UPDATE users SET $upgrade=$upgrade+'1' WHERE id='$row[userid]'");
    mysql_query("DELETE FROM buildup where id=$row['id']");
        }
        
    }

    //run cron
    buildup_cron();
    ?>
    Of course, that's assuming there's an id column in buildup.

  3. #3
    Join Date
    Jun 2007
    Location
    England
    Posts
    448
    cheers , thanks allot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles