如何循环子类别及其类别?
编辑:好的,让我更清楚一点,我有一个 html 文件名 file.html 它是这样的:
{category} {sybcategory}
和我有一个索引文件,如下所示:
类模板 { var $页;
function add_file($file){
$this->page = file_get_contents($file);
return $this->page;
}
function vars($array)
{
foreach($array as $key => $value)
{
$this->page = str_replace('{'.$key.'}', $value, $this->page);
}
echo $this->page;
}
$
template = 新模板();
$template->add_file('file.html');
$template->file_vars(array('category' => $row_cat['title'], 'subcategory' => $row_subcat['title']));
现在,这只输出标题和子类别一次,我如何循环它,而且我没有在这里添加 mysql 查询,因为我不想浪费你更多的时间,如果你知道怎么做,请告诉我。
EDIT: ok let me be a bit more clear i have a html file name file.html it is like this:
{category}
{sybcategory}
and i have a index file which is like this:
class template
{
var $page;
function add_file($file){
$this->page = file_get_contents($file);
return $this->page;
}
function vars($array)
{
foreach($array as $key => $value)
{
$this->page = str_replace('{'.$key.'}', $value, $this->page);
}
echo $this->page;
}
}
$template = new template();
$template->add_file('file.html');
$template->file_vars(array('category' => $row_cat['title'], 'subcategory' => $row_subcat['title']));
now, this only outputs the title and the subcategory only once how do i loop that and i have not added the mysql query here because i don't wanna waste your more time please if you know how to do it then let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里:
这将为您提供一个数组的数组。第一个数组包含类别标题作为键,它们将包含所有子类别标题的数组。
Here you go:
This will give you an array of arrays. The first array contains the category titles as keys and they will contain an array of all the sub category titles.
把你在那里的所有东西都存储起来怎么样?
这样,您将拥有一个包含所有猫及其子猫的数组。
希望它有所帮助:)
编辑:我想我误解了你的问题,我回答的内容涵盖了如何对它们进行分组,但你最终要求的是一个模板引擎,例如Smarty,它不能“总结” “在 Stackoverflow 的一个答案中,您需要先构建引擎,然后才能使用 {catArray} 之类的东西。
How about storing everything within those whiles you have there?
This way you'll have a single array with all the cats followed by their subcats.
Hope it helps a bit :)
EDIT: I think I misunderstood your question, what I answered covers how you can group them, but what you're asking in the end is a template engine such as Smarty, which can't be "summarized" in a single answer here in Stackoverflow, you'd need to build the engine before you can use something like {catArray}.