I have this mysql query that I would like to make mysqli compatible and in the same time more efficient? Thanks a lot in advance!
My code is
$query = "SELECT COUNT(*) as num FROM table";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$limit = 15;
$start = 0;
$sql = mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT $start, $limit") or die(mysql_error());
You can get it in 1 Statement with use SQL_CALC_FOUND_ROWS
Try:
$sql = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM table ORDER BY id DESC LIMIT $start, $limit") or die(mysql_error());
and after you get your rows you can get the Total Row count with
SELECT FOUND_ROWS();
[Doku SQL_CALC_FOUND_ROWS]
you just need to write mysqli everywhere you wrote mysql. change mysql_fetch_array > mysqli_fetch_array
mysql_query > mysqli_query