I have this code
$dbh = new PDO('mysql:host=localhost;dbname=odesk', 'root', '123456');
$sth = $dbh->prepare("SELECT id,msisdn from new_r4 limit 1,10");
$sth2 = $dbh->prepare("SELECT status from flag where id = 1");
$sth->execute();
$sth2->execute();
while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
$result2 = $sth2->fetch(PDO::FETCH_ASSOC);
$flag = $result2['status'];
$the_number = $result['msisdn'];
$id = $result['id'];
while ($flag == 0) {
echo 'Waiting.......' . PHP_EOL;
sleep(1);
}
//Part of the condition,just added
while ($flag == 1) {
echo $the_number . ' ' . $id .' ' . PHP_EOL;
sleep(1);
}
}
which is a a cli script that displays some numbers from my address book if a certain condition is met.If a the flag is 0
then no number shall be displayed and when the flag is 1
,then display the number.
The problem is,i can't find the right condition to use after
while ($flag == 0) {
echo 'Waiting.......' . PHP_EOL;
sleep(1);
}
The if
, else
and case
do not wait up until the flag is 1.
What condition can i use to get the script to display the numbers when $flag == 1
?.