-3

Can someone please tell me why this isn't working. When I run the query in PHPMYADMIN it reports the correct value.

// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if (mysqli_connect_errno())
  {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($conn, "SELECT COUNT('id') AS RowCount FROM 'needs' WHERE ('status'=100)");


echo $result;

2 Answers2

1

You're combining mysqli and mysql_ functions. Either use mysqli, or use mysql_. But note, mysql_ functions are deprecated for security reasons.

Guerila
  • 11
  • 2
-1

Hi You need this code.

//If the query returns more 1 row you must use this.
...
$query = "USE database_name; SELECT COUNT(`id`) AS RowCount FROM `needs` WHERE (`status`=100);"

$result= mysql_query($query) or die(mysql_error());

if ($row= mysql_fetch_array($result))
   {  
     DO{
        echo $row["RowCount "];  
        }WHILE ($row=mysql_fetch_array($result));
    }
// now if you query returns only 1 wor use this.

$result= mysql_query($query) or die(mysql_error());
$rowQry= mysql_fetch_array($result);
echo $rowQry["RowCount "];

Luky