【发布时间】:2011-04-08 12:01:07
【问题描述】:
我需要输出所有书架上的所有书籍。下面的代码只输出最后一本书。任何帮助都会有所帮助。
我的控制器:
function index()
{
$data['books'] = $this->_books();
$this->load->view('books_view', $data);
}
function _books() {
$xml = simplexml_load_file('books.xml');
foreach ($xml->shelfs as $shelf)
{
$result = '<optgroup label="'.$shelf['id'].'">';
foreach ($shelf->books as $book)
{
$result .= '<option value="'.$book->title.'">'.$book->title.'</option>';
}
$result .= '</optgroup>';
}
return $result;
}
我的看法:
echo form_open('books#');
echo '<select name="books[]" multiple="multiple" onClick="this.form.submit()">';
echo $options;
echo '</select></form>';
我的输出:
只有最后一个架子是“Z”。
我的 XML 数据:
<?xml version="1.0" encoding="UTF-8" ?>
<library>
<shelfs id="A">
<strip>
<title>Book Title #1 for A</title>
<author>Author Name #1 for A</author>
</strip>
<strip>
<title>Book Title #2 for A</title>
<author>Author Name #2 for A</author>
</strip>
</comics>
...
<shelfs id="Z">
<strip>
<title>Book Title #1 for Z</title>
<author>Author Name #1 for Z</author>
</strip>
<strip>
<title>Book Title #2 for Z</title>
<author>Author Name #2 for Z</author>
</strip>
</comics>
</library>
【问题讨论】:
标签: php xml codeigniter