I have a problem,im trying to convert php standard to CodeIgniter, But I dont know how to convert ths code, please help, and thanks a lot.
<?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
}
?>
Hope this will help you :
You don’t need to use db_select
if you have single database, if multiple database you only need to use a different database on the same connection. You can switch to a different database when you need to using this $this->db->db_select('ardefa');
You can do like this :
//$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);
*/
}
Use $result like this :
foreach($result as $row)
{
echo $row;
}
Or can also do it like this :
//$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();
*/
}
Try this hope it will help you
MODEL
public function your_function(){
return $this->db->get('borneo')->reslut_array();
}
CONTROLLER
<?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 } } ?>