I'm struggling to find a solution to this.
I have a select statement that returns 5 rows based on a condition (WHERE job position).
UserNames column: John Jake Alvin Allan Robert
I wanted a column where it will show the row number, hence:
RowNumber: 1 2 3 4 5
UserNames column: John Jake Alvin Allan Robert
I figured that the query is this:
set @rownumber=0;
select (@rownumber:=@rownumber+1) AS rownumber FROM (select * from usernames WHERE position='Team Lead') as t;
It works in MySQL Workbench as expected. The problem is I cannot seem to output the result to PHP. It's throwing an error:
mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given
My PHP code is this:
$userQuery = "set @rownumber=0;";
$userQuery .= "select (@rownumber:=@rownumber+1) AS rownumber FROM (select * from usernames WHERE position='Team Lead') as t";
$userQueryResult = mysqli_query($dbConnection, $userQuery);
$row = mysqli_num_rows($userQueryResult);
Note that I also used mysqli_multi_query
but to no avail.