0

I have this MySQL query that has to run when the page is loaded, however not all users have the data required to return anything, this gives out a massive error.

Is there anyway i can handle this error so when the query doesn't return anything, i can just return say "0" in the function. Here is the code;

function getTimesUp($email) {   
    $query1 = mysql_query("SELECT uptime FROM info WHERE user='$email'");
    $uptime1 = mysql_result($query1, 0);

    return $uptime1;
}

Thanks!

2 Answers 2

1

Check the query to see if it returned a 0 number of rows.

function getTimesUp($email)
{   
  $query1 = mysql_query("SELECT uptime FROM info WHERE user='$email'");

  if(mysql_num_rows($query1) == 0)
  {
   return 0;
  }
  else
  {
    $uptime1 = mysql_result($query1, 0);
    return $uptime1;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You could just check whether mysql_num_rows() is greater than zero.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.