Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I show the x row of the y column?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

label2: Mandrin

label3: Extracteur

…….

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading