...

View Full Version : Check if row exists in table



The_Return
08-24-2009, 02:29 AM
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
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);

}

?>

Fumigator
08-24-2009, 04:56 PM
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".

The_Return
08-24-2009, 05:36 PM
Ok I updated the script and removed all the aim parts to see the output. Its displays it double like this



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?

Fumigator
08-24-2009, 05:55 PM
There are two rows in your friends table that match the select conditions.

The_Return
08-24-2009, 06:18 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum