My table is looks like
Id | Topic | Sentence |
---|---|---|
1 | bla bla..1 | |
2 | YouTube | bla bla..2 |
3 | Amazon | bla bla..3 |
4 | bla bla..4 | |
5 | bla bla..5 | |
6 | YouTube | bla bla..6 |
Now I want just like the Udemy course curriculum listing. Under each topic, list all the sentence in a respective order.
Eg. of what I want,
Google ^
bla bla..1
bla bla..4
bla bla..5
YouTube ^
bla bla..2
bla bla..6
Amazon ^
bla bla..3
NB: No Google should be come first, all is ordered according to the id I think. Idea: Just like Udemy in one of their course there is introduction topic and there are some videos under that topic and there is another topic called basic and there are some contents/videos under that topic too and etc at the last there is end course topic and under that topic there are some listed contents/videos.
So now assuming the topic I'm saying are the topic of the above table and and the contents are the sentence of the above table.
I want to display the topic called Google in this case and display the sentence of it under that topic. same goes to YouTube and soon...
What I've tried is: echoing out all the topic and the sentence but the problem here is I've displayed all the contents under each topic which is there are 3 Google, 2 YouTube and one Amazon topics over their respective sentences.
$select = $db_conn->query("SELECT * FROM contents WHERE email = '$email' ORDER BY id");
foreach($select as $select_data){
$topic = $select_data['topic'];
$sentence = $select_data['sentence'];
$id = $select_data['id'];
echo "<h2>$topic</h2>"; // this should be echo out once only if the same topic is there
echo "<p>$sentence</p>";
}
So How can I solve this problem?