我使用YII框架,我想将MySQL查询的结果放在index.php的表中。
MySQL查询已经很好了:
SELECT categories.name,
systemes.name,
systemes.etat_de_base,
maintenances.name,
maintenances.date,
maintenances.duree
FROM systemes_maintenances
LEFT JOIN systemes
ON systemes_maintenances.id_systemes = systemes.id_systemes
LEFT JOIN categories
ON systemes.id_categories = categories.id_categories
LEFT JOIN maintenances
ON systemes_maintenances.id_maintenances = maintenances.id_maintenances;
我的PHP页面目前看起来像这样:
<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<!--<h1>Welcome to <i><?php echo CHtml::encode(Yii::app()->name); ?></i></h1>
<p>Congratulations! You have successfully created your Yii application.</p>
<p>You may change the content of this page by modifying the following two files:</p>
<ul>
<li>View file: <code><?php echo __FILE__; ?></code></li>
<li>Layout file: <code><?php echo $this->getLayoutFile('main'); ?></code></li>
</ul>
<p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p>-->
<table>
<caption>État des systèmes</caption>
<tr>
<th>Catégorie</th>
<th>Nom</th>
<th>État actuel</th>
<th>Maintenance prévue</th>
<th>Début de l'incident</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
我想在空<td> </ td>
。
有没有人知道如何在没有jQuery的情况下做到这一点?
答案 0 :(得分:2)
由于您使用的是Yii框架,因此您可以使用CGridView组件。这提供了一组很好的功能,例如排序,分页和过滤。 检查以下链接以获取示例用法。 http://www.yiiplayground.com/index.php?r=UiModule/dataview/gridView
答案 1 :(得分:2)
要连接到数据库,并且在配置yii中定义了连接。必须添加到页面顶部的两行代码。
$sql = 'querySQL';
$connection=Yii::app()->db;
$dataReader=$connection->createCommand($sql)->query();
答案 2 :(得分:0)
他们是一个教程如何在Mysql中显示PHP中的数据。
链接:http://hightechnology.in/how-to-display-data-in-php-from-mysql/
它可以帮到你。
答案 3 :(得分:0)
试试这样:
$query = "SELECT categories.name,
systemes.name,
systemes.etat_de_base,
maintenances.name,
maintenances.date,
maintenances.duree
FROM systemes_maintenances
LEFT JOIN systemes
ON systemes_maintenances.id_systemes = systemes.id_systemes
LEFT JOIN categories
ON systemes.id_categories = categories.id_categories
LEFT JOIN maintenances
ON systemes_maintenances.id_maintenances = maintenances.id_maintenances";
$count= Yii::app()->db->createCommand($query)->queryScalar();
$dataProvider = new CSqlDataProvider($query, array(
'totalItemCount'=>(int) $count,
'keyField' => 'SOME_UNIQUE_ID_FROM_THE_SQL',
'pagination'=>array( 'pageSize'=>30, ),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'yourGrid',
'dataProvider'=> $dataProvider,
));
您必须自己自定义网格,以便它只显示您需要的内容,但您可以在CGridView的Yii文档中找到它
答案 4 :(得分:-2)
我对YII框架不太确定,但这绝对可以帮到你。
让mySql查询的结果在变量 $ result
中现在,以这样的while / for循环开始:
<?php
while ($row=mysqli_fetch_array($result)){
//Do something with the $row variable data
?>
<td>Some Data</td>
<td>echo $row["SomeColoumn1"];</td>
<td>echo $row["SomeColoumn2"];</td>
<td>echo $row["SomeColoumn3"];</td>
<td>echo $row["SomeColoumn4"];</td>
<?php
}
?>
这应该根据需要打印表格的所有行,并相应地在之前和之后添加表格和 部分。