我写了以下代码:
foreach ($key['options'] as $options) {
$contents = str_replace("[OPTION]",$options['text'], $contents);
}
$result= '';
foreach ($key['motor'] as $motor) {
$nm = str_replace ("[NAME]",$motor['name'], $contents);
$cnt = str_replace ("[COUNT]",$motor['count'], $contents);
$result .= $cnt ." " .$nm. " ";
}
echo $result;
$paginas .= $contents;
echo $paginas;
我的'$ key'看起来像是:
function getCarDetail($data){
$files = @file_get_contents("./assets/template/_detail.html");
$contents = "";
$paginas = "";
foreach ($data as $key) {
$contents = str_replace("[PHOTO]",$key['photo'], $files);
$contents = str_replace("[NAME]",$key['name'], $contents);
$contents = str_replace("[TYPE]",$key['type'], $contents);
foreach ($key['step'] as $step) {
$contents = str_replace("[STEP]",$step['text'], $contents);
}
foreach ($key['comments'] as $comments) {
$contents = str_replace("[COMMENTS]",$comments['text'], $contents);
}
$result='';
foreach ($key['motor'] as $motor) {
$nm = str_replace ("[NAME]",$motor['name'], $contents);
$cnt = str_replace ("[COUNT]",$motor['count'], $contents);
$result .= $cnt ." " .$nm. " ";
}
echo $result;
$paginas .= $contents;
}
echo $paginas;
}
$layout = new _layout(getCarDetail($data, $key), DETAILPAGE);
echo $layout->render();
我有一个关于汽车的(测试)网站,其中包含3列彼此相邻的列。每辆车有一列我通过MySQL请求的信息。这很好。
现在有了$ result,我想向这些列添加更多信息,但每辆车有多个选项。它不是将所有$结果列在一列中,而是为每个项目添加一个新列。
我的目标是获得一个概述,其中$ result的所有结果都列在1列中。
HTML代码如下所示:
<div class="col-md-12" align="center">
<dt>
</dt>
<img src="[PHOTO]" img width="30%" img height="50%" align="center"/>
<dl>
<dt>
NAME
</dt>
<dd>
[NAME]
</dd>
<dt>
TYPE
</dt>
<dd>
[TYPE]
</dd>
<dt>
MOTOR
</dt>
<dd>
[COUNT] [MOTOR]
</dd>
</dl>
</div>
_layout:
class _layout {
private $template;
public function render() {
return($this->template);
}
private function homepage($data) {
$this->template = str_replace("[TITLE]", "Overview", $this- >template);
$this->template = str_replace("[CONTENT]", $data, $this->template);
}
private function detailpage($data) {
$this->template = str_replace("[TITLE]", "Cars", $this->template);
$this->template = str_replace("[CONTENT]", $data, $this->template);
}
private function list($data) {
$this->template = str_replace("[TITLE]", "List", $this->template);
$this->template = str_replace("[CONTENT]", "!", $this->template);
}
public function __construct($data, $type) {
$this->template = file_get_contents(TEMPLATE);
switch($type) {
case HOMEPAGE: {
$this->homepage($data);
break;
}
case DETAILPAGE: {
$this->detailpage($data);
break;
}
case LIST: {
$this->list($data);
break;
}
default: {
$this->homepage($data);
break;
}
}
}
}
?>
任何人都知道如何解决这个问题?
答案 0 :(得分:0)
CSS类col-md-12
表示您正在使用BOOTSTRAP布局。 Bootrap提供易于使用的网格布局,其中包含列(tutorial about boostrap grid)。可以使用col-md-4
类创建具有e列的网格布局(数字表示列的宽度,整行的宽度为12)。由于您需要相反的(只有一列),您可以删除所有的boostrap类,或者使用类col-md-12
确保每个项跨越整行。