By Fluffy Convict on
In a module that I am developing, I use a piece of code to generate a table:
while ($story = db_fetch_object($result)) {
$rows[] = story_list_row($type, $fields, $story);
}
// ...
$output = theme_table($header, $rows);
Currently, I only return one row ($row1):
function story_list_row($type, $fields, $story) {
$row1[] = array('data' => l($story->name, "user/$story->uid"));
$row1[] = array('data' => date('d', $story->created), 'nowrap' => 'nowrap');
$row2[] = array('data' => 'foo!', 'rowspan' => 2);
return $row1;
}
Now, I want to return 2 rows ($row1 and $row2), since they contain related information. The resulting table should look like this:
+--------------+-----+
| story_name 1 | mon |
+--------------+-----+
| foo! |
+--------------+-----+
| story_name 2 | fri |
+--------------+-----+
| foo! |
+--------------+-----+
| story_name 3 | tue |
+--------------+-----+
| foo! |
+--------------+-----+
Comments
Sorry, wrong button ... so
Sorry, wrong button ... so my question is how I should alter my code to return 2 table rows at once?
Here is one way
I would pass rows to your function () like this
And change story_list_row() like this
I then get an error: "Fatal
I then get an error: "Fatal error: Cannot use [] for reading in C:\xampp\htdocs\odisys\modules\story\story.module on line 344". Line 344 is where is says "$rows[] = $row1[]". Any thoughts?
My comment does not have
My comment does not have line with
$rows[] = $row1[], it does have$rows[] = $row1;so the problem may be the extra[].It works like a charm
Thanks!
Just merge the two arrays
Just merge the two arrays together:
________________________
"Creativity is knowing how to hide your resources" - Albert Einstein.
no, by merging the two
no, by merging the two arrays you only create one row with additional cells :)