我有一个问题,我试图将php标准转换为CodeIgniter,但我不知道如何转换这个代码,请帮助,非常感谢。
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("ardefa");
$borneo=mysql_query("select* from borneo");
while($row=mysql_fetch_array($borneo))
{
?>
<a href="#"><li><img src="
<?php
$page = isset($_GET['page']) ? ($_GET['page']):"";
if ($page =='borneo')
{
echo $row["img"];
}
?>">
</li></a>
<?php
}
?>
发布于 2018-06-04 16:49:02
希望这能对你有所帮助:
如果你只有一个数据库,你不需要使用db_select
,如果你有多个数据库,你只需要在同一个连接上使用不同的数据库。当您需要使用此$this->db->db_select('ardefa');
时,可以切换到其他数据库
你可以这样做:
//$this->db->db_select('ardefa');
$this->db->select('*');
$this->db->from('borneo');
$query = $this->db->get();
if ($query->num_rows() > 0 )
{
/*for multiple array*/
$result = $query->result_array();
/*print here to see the result
print_r($result);
*/
}
像这样使用$result:
foreach($result as $row)
{
echo $row;
}
或者也可以像这样做:
//$this->db->db_select('ardefa');
$query = $this->db->get('borneo');
if ($query->num_rows() > 0 )
{
/*for multiple array*/
$result = $query->result_array();
/*for single array
$row = $query->row_array();
*/
}
发布于 2018-06-04 16:54:41
试试这个,希望它能帮到你
模型
public function your_function(){
return $this->db->get('borneo')->reslut_array();
}
控制器
<?php
$this->load->model('model-name');
$data = $this->model-name->model_function();
foreach($data as $row){
if(isset($_GET['page']) && $_GET['page'] == "borneo"){ ?>
<a href="#"><li><img src="<?php echo $row['img']?>" /></li></a>
<?php } } ?>
https://stackoverflow.com/questions/50676511
复制相似问题