Search code examples
phpmysqlcounthtml-heading

If at least one ocurrence of that echo this


I am writing a resume script and I need the heading "Reference" to be inserted if a mysql query finds at least one occurence of the current job_id in the table "references", how would I be able to that?


Solution

  • You can determine the number of rows returned by a query with mysql_num_rows() or $mysqli_result->num_rows if you're using MySQLi. Which I recommend.

    Then it's a simple if:

    if ($result->num_rows) {
      echo 'References';
      // do more stuff...
    }