Help on selecting function


#1

Hi Guys

I have table tbl_helloworld and field are

ID | Country | Note |
01 | US | Some Text 1
02 | US | Some Text 2
03 | US | Some Text 3
04 | CA | Some Text 4
05 | CA | Some Text 5

What Function should I use to show like result below (i dont want to repeat US 3 time)
US:
Some Text 1
Some Text 2
Some Text 3
Some Text 4

CA:
Some Text 4
Some Text 5

My Code is:
$con=new mysqli(“localhost”,“root”,"",“helloworlddb”);
$st=$con->prepare(“select * from tbl_helloworld”);
$st->execute();
$rs=$st->get_result();
while($row=$rs->fetch_assoc())
{
echo $row[‘note’];

            }

#2

Not sure what you mean. And that display doesn’t match your data.
First steps, learn some on SQL: https://www.w3schools.com/sql/


#3

Order your query by Country (and optionally also by ID or Note). Then just iterate over it. To show headers you could use a temporary variable to hold $lastHeader and check if the current row[‘Country’] === $lastHeader. If not then print a header and set $lastHeader to the new row