FUNKAM35 Posted July 31, 2015 Share Posted July 31, 2015 $total_results = mysqli_result(mysqli_query("SELECT COUNT(*) as Num FROM property WHERE $where "),0) ; $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM property WHERE $where "),0) ; Hi, Please can anyone help I have changed MySQL_ to mysqli_ but I am getting fatal error on above line, please can anyone help Thanks Quote Link to comment Share on other sites More sharing options...
requinix Posted July 31, 2015 Share Posted July 31, 2015 You cannot simply add an 'i'. They are different functions. You need to actually learn about mysql (so you know what you have now) and mysqli (so you know what you need to have). Quote Link to comment Share on other sites More sharing options...
Solution VanityCrush Posted August 1, 2015 Solution Share Posted August 1, 2015 Hi there, mysql_query is deprecated and it will be removed on future PHP versions. Use mysqli_query instead. mysqli_query takes two parameters - the database connection and the actual query, therefore you have to include the database connection file in your code. For example : $dbCon = mysqli_connect("localhost", "root", "password", "database_name") or die(mysqli_error()); As you can see, I am storing the database connection in a variable. To implement this into mysqli_query we now need to store the actual query in a variable (you could also write the full query as the second parameter but it will make your code less readable) $sql = "SELECT COUNT(*) as Num FROM property WHERE $where "; Now to implement this with mysqli: $query = mysqli_query($dbCon, $sql); For mysql_result you can use the below function which is basically a mysqli_result: function mysqli_result($res,$row=0,$col=0) { $numrows = mysqli_num_rows($res); if ($numrows && $row <= ($numrows-1) && $row >=0) { mysqli_data_seek($res,$row); $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res); if (isset($resrow[$col])) { return $resrow[$col]; } } return false; } After all this, your line should look like: $total_results = mysqli_result($query, 0); Hope this helps in a way or another. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.