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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts

    Check if row exists in table

    I have a script where the user submits a message and it goes to the table "jobs" where it puts the message and hostid key. The second script I wanna cron so every 5 minutes it will check if their is a new job and if their is a job to go ahead and complete it then delete it and then check again ..loop and so on.

    PHP Code:
    <?php
    ob_implicit_flush
    (true); 
    //include("aimclassw.php"); //Toc
     
     
    //check if their are jobs
    $query "SELECT * FROM jobs WHERE status = '0'";
    $result mysql_query($query) or die(mysql_error());

    while(
    $row mysql_fetch_array($result)) {

    $message $row['message'];
    $hostid $row['hostid'];


    //select all the aims with the host id given
    $q "SELECT aim FROM friends WHERE hostid = '$hostid'";
    $re mysql_query($q) or die(mysql_error());

    while(
    $r mysql_fetch_array($re)){

    echo 
    "The message is $message the sender is $hostid";

      }
    //End while loop
     

    $query2 "DELETE FROM `jobs` WHERE `message` = '$message' AND `hostid` = '$hostid'";
    $result2 mysql_query($query2); 



    ?>
    Last edited by The_Return; 08-24-2009 at 05:19 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    How about add a status code to the jobs table so you can update that table after you process a job? New jobs give a status of "NEW" to, when a job is finished change the status to "FINISHED". Your cron query will then pick up only those jobs with status of "NEW".

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Ok I updated the script and removed all the aim parts to see the output. Its displays it double like this

    Code:
    The message is This is a test the sender is c9723097991b56826b1b854f61c177f3The message is This is a test the sender is c9723097991b56826b1b854f61c177f3
    and deletes it fine. But how can I stop it from showing it twice?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    There are two rows in your friends table that match the select conditions.

  • #5
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts
    in that case it should be working fine because each hostid has a screen name attached to it and I only have 2 friends so it loops it twice. Ok looks like the problem was looping the sign in of the aim
    Last edited by The_Return; 08-24-2009 at 05:33 PM.


  •  

    Posting Permissions

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