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