I'm working on a photo-gallery-like project right now, and am running into some issues manipulating a multi-dimensional array. First, here's the info that I'm working with:
PHP Code:
mysql> select * from instance where gallery_id = 88 order by row_number,position;
+-------------+------------+----------+------------+----------+
| instance_id | gallery_id | image_id | row_number | position |
+-------------+------------+----------+------------+----------+
| 36 | 88 | 3 | 1 | 1 |
| 37 | 88 | 12 | 1 | 2 |
| 38 | 88 | 0 | 1 | 3 |
| 39 | 88 | 4 | 1 | 4 |
| 40 | 88 | 11 | 2 | 1 |
| 41 | 88 | 3 | 2 | 2 |
| 42 | 88 | 5 | 2 | 3 |
| 43 | 88 | 0 | 2 | 4 |
+-------------+------------+----------+------------+----------+
8 rows in set (0.00 sec)
In "Gallery 88", there are eight images, on two different rows. The order in which they should appear is the "position". What I would like to do is dump this data into a multi-dimension array in such a format that: $row[row_number][position]['image_id'] would be the image id of the image in the first position of the first row. For example, $row[2][1]['image_id'] == 12, and is the first image of the second row.
The sql wrapper that I use returns an array of an array as the results ( $results[0-254]['column_name'] ), and what I'm currently attempting to do is to select each row, and push each row into a "rows" array, like so:
PHP Code:
function format_instances( $gallery_id ) {
global $db, $instance_table;
$next_row = get_current_row( $gallery_id );
for ( $x=1; $x < $next_row; $x++ ) {
$rows[] = $db->select_all( $instance_table, "WHERE gallery_id=" . $gallery_id .
"AND row_number=" . $x );
}
return $rows;
}
This doesn't seem to be working -- the result of the following code snippet is an endless loop of some sort which does not return the proper image_id value:
PHP Code:
$gal = format_instances( $gallery_id );
for ( $x=1; $x < $next_row; $x++ ) {
for ( $w=0; $x < $positions; $w++ ) {
$image_id = $gal[$x][$w]['image_id'];
error_log( "blizzaaahh: " . $image_id );
}
}
It's past 6 am now (and I'm still awake), so I am probably missing something incredibly simple, but maybe I'm not? Thanks in advance.