Home > Back-end >  How can I show the x row of the y column?
How can I show the x row of the y column?

Time:07-08

I selected 10 values of my datatable I want to display eatch one in a label form: This is my code:

$result1 = mysqli_query($con,"SELECT * FROM tbl_ou group by reference  order by sum(quantite) desc LIMIT 10;");
while($row1 = mysqli_fetch_array($result1)){
echo $row1[5];

the result: Mandrin Mandrin Extracteur Mandrin Obturateur Mandrin Câbleadapt Câble adapt Mandrin Extracteur

What I want: label1: Mandrin

label2: Mandrin

label3: Extracteur

.......

CodePudding user response:

As CBroe said, you can add a counter that increments with each while loop.

$result1 = mysqli_query($con,"SELECT * FROM tbl_ou group by reference  order by sum(quantite) desc LIMIT 10;");
$i = 1; //This is the counter variable
while($row1 = mysqli_fetch_array($result1)){
    echo "Label ".$i.": ".$row1[5];
    $i  ;
}
//Excpected Output for first loop:
//Label 1: Mandarin
  • Related