mardi 26 avril 2016

If rowCount empty, try again

I am running a query from a table whose data gets refreshed (deleted and re-inserted) every 30 seconds.

I want my query (which outputs row count) to detect that the row count is null (or zero) and re-run the query. Maximum retries: 5.

And after 5th retries, if it's still zero, I want the row count to print "0".

I know it's a loop but I don't know how to loop it from within the if for row.

<?php
$con=mysqli_connect("HOST","USERNAME","PASS","TABLENAME");


$sql="SELECT id FROM candyshop WHERE candy <= 5 AND sugartype ='hard'";

 $number = 0; //init count for loop

 if ($result=mysqli_query($con,$sql))
  {

  $rowcount=mysqli_num_rows($result);



  printf($rowcount); //print number of rows

 mysqli_free_result($result);

 $number = $number+1; //increment number for loop

 }

mysqli_close($con);
 ?>

Aucun commentaire:

Enregistrer un commentaire