I have a database table like below:
id | igroup | title | url | text
1 | gr1 | Title 1 | urltoimage1 | text1
2 | gr1 | Title 2 | urltoimage2 | text2
3 | gr2 | Title 3 | urltoimage3 | text3
4 | gr2 | Title 4 | urltoimage4 | text4
I mean, i want to have an multidimensional array (for above structure) like below;
$result[gr1] = [Title 1|urltoimage1][Title 2|urltoimage2]
$result[gr2] = [Title 3|urltoimage3][Title 4|urltoimage4]
Finally, I’ll send this $result array to page via JSON.
So, in my page I’ll arrange these values for classified image gallery, like:
Group 1(caption text)
--------
image1 image2 (clickable images)
Group 2(caption text)
--------
image3 image4 (clickable images)
Edit: i corrected group field by igroup.
Question revised.
You will need to fetch the results using the
ORDER BYstatement added to your query.Example code:
This will build up a nice
$groupsarray. To parse the array created above, you might either use Iterators or simpleforeachconstructs.This will give you a nice output like this below:
No longer applies: Also, you should refrain from using
GROUPas a field name, as it is one of the reserved MySQL words.Edit: I have also corrected the field name to
igroup.