Getting first row data without while loop

Posted under » PHP » MySQL » Django on 19 Oct 2022

There will be times when you want to create a header or just get something from the first row without having to loop or a while etc.

 if ($result = $dbhandle -> query("SELECT stage, question, student_name 
  FROM mth108c where student_id = $sid")) {
     $tow = mysqli_fetch_row($result);
     echo "<h2>Student name : ".$tow[2]."</h2>";

Take note that $tow is fetching the 3rd object or column which is 'student_name'.

In Django, they have simplified it with the first and last function. eg



web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data