Hi astonecipher
Having got my ‘conntest.php’ script working for PHP7 and MySQLi (Thanks to you), I have been trying to get the ‘GROUP BY’ bit working also. To this end, I have added this ‘GROUP BY’ test to the bottom of my ‘conntest.php’ script.
If I run the script as below (GROUP BY IGNORED), I get the table results but not grouped and no warning message
If I run the alternate script (GROUP BY SQL), I just get the warning:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/csg/conntest.php line 25.
This refers to the $resultcheck line which actually works as it correctly reports 1335 rows.
I have specified two fields in the SELECT, one of which is used in the GROUP BY. Now a single GROUP BY upsets everything. Does GROUP BY ever work with PHP7 & MySQLi?
Cheers
Gary
//=========================================
//***** GROUP BY *****
//=========================================
// GROUP BY IGNORED
$sql=“SELECT timesheet_id
,user_key
FROM tbl_timesheet”;
// -----------------------------------------------
// GROUP BY SQL
// $sql="SELECT timesheet_id
,user_key
FROM tbl_timesheet GROUP BY user_key
";
// -----------------------------------------------
$result = mysqli_query($conn,$sql);
$resultcheck = mysqli_num_rows($result);
echo “There are $resultcheck rows in the timesheet table
\n”;
// The answer is 1335. This is correct.
if ($resultcheck > 0) {
while ($row = mysqli_fetch_array($result))
{
$str.="<tr>";
$str.="<td>".$row['timesheet_id']."</td>";
$str.="<td>".$row['user_key']."</td>";
$str.="</tr>";
}
}
echo $str;