0

I'm not sure where I'm going wrong here. I've searched similar issues on here with no luck. Any help would be greatly appreciated. Thanks!

$check = "SELECT Number FROM advisors";
$result = mysqli_query($check);
$count = mysqi_num_rows($result);

echo $count;
4
  • If you only want the number of rows SELECT count(*) as cnt FROM advisors Commented Dec 7, 2017 at 19:45
  • 2
    Also, mysqli_query takes a mysqli object as its first parameter. Commented Dec 7, 2017 at 19:46
  • 1
    You have a typo, mysqi_num_rows should be mysqli_num_rows. Commented Dec 7, 2017 at 19:51
  • oh no still mysqli_query around the block Commented Dec 7, 2017 at 20:00

2 Answers 2

2

You should use php prepare statement like this

$count  = 0;
$mysqli = new mysqli(host, dbUser, dbPassword, dbName);
mysqli_set_charset($mysqli, "utf8");
$sql    = "select count(*)  from advisors";
if ($stmt   = mysqli_prepare($mysqli, $sql))
{
    mysqli_stmt_execute($stmt);
    mysqli_stmt_store_result($stmt);
    mysqli_stmt_bind_result($stmt, $c);
    if (mysqli_stmt_fetch($stmt))
    {
        $count = $c;
    }
    mysqli_stmt_close($stmt);
}
return $count;

For more information, here is the link for php prepare statement Documentation of php prepare statement

Sign up to request clarification or add additional context in comments.

1 Comment

It's helpful to the asker to include a link to the documentation for the method that you recommend with your answers: php.net/manual/en/mysqli.quickstart.prepared-statements.php
0

You should use COUNT in query and see if it works, "SELECT COUNT (number) as number FROM advisors"; By the way, I noticed a typo in $count, it should be $count = mysqli_num_count($result).

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.