I need help to make the best query posible here. I have the following Database:
+----+--------------+-----------------+------------------------------+
| id | reference_id | reference_field | value |
+----+--------------+-----------------+------------------------------+
| 1 | 6215 | title | Best recipe |
| 2 | 6215 | introText | Intro for best recipe |
| 3 | 6215 | fullText | Full text for best recipe |
| 4 | 6216 | title | Play Football |
| 5 | 6216 | introText | Intro for play football |
| 6 | 6216 | fullText | Full text for play football |
+----+--------------+-----------------+------------------------------+
I need to make a query where I group by reference_id and I should print the value by the reference_field, example of the output info:
Best recipe
Intro for best recipe
Full text for best recipe
Play Football
Intro for play football
Full text for play football
UPDATE To accomplish this, I will print the query on the following way with PHP:
$result = $config->mysqli->query("SELECT * FROM table_name ORBER BY reference_id");
while($row = $result->fetch_array()) {
echo ('<h1>'.$row["title"].'</h1>');
echo ('<h1>'.$row["introText"].'</h1>');
echo ('<h1>'.$row["fullText"].'</h1>');
}
With the query above, I get all the records one by one (not grouped by the reference_id), in other hand if I do the query
SELECT * FROM table_name GROUP BY reference_id
How do I get the 3 values (title, introText, fullText) to print on the loop interaction in PHP?
As you can see with a normal "order by" or "group by" does not produce the proper result to print the values on the loop. What I see here is that on the result I should print the values of 3 records by each loop interaction in PHP instead print 3 fields of each records, does it make sense?