如何将此代码转换为可接受的codeigniter代码:
mysql_select_db($database_connection_ched, $connection_ched);
$query_Institutions = "SELECT * FROM tb_institutional_profile ORDER BY tb_institutional_profile.institution_name ASC";
$Institutions = mysql_query($query_Institutions, $connection_ched) or die(mysql_error());
$row_Institutions = mysql_fetch_assoc($Institutions);
$totalRows_Institutions = mysql_num_rows($Institutions);
<td width="192"><select name="institution_id">
<?php
do {
<option value="<?php echo $row_Institutions['institution_id']?>" ><?php echo $row_Institutions['institution_name']?></option>
<?php
} while ($row_Institutions = mysql_fetch_assoc($Institutions));
?>
</select></td>
答案 0 :(得分:1)
首先,在database.php
文件夹中正确设置application/config/
,然后在控制器/型号上自动加载或使用$this->load->database();
<?php
$this->db->order_by("institution_name", "asc");
$result = $this->db->get('tb_institutional_profile');
$totalRows_Institutions = $this->db->count_all_results();
?>
<td width="192"><select name="institution_id">
<?php
foreach($result->result() as $row ){
?>
<option value="<?= $row->institution_id ?>">
<?= $row->institution_name ?>
</option>
<?php
}
?>
</td>
答案 1 :(得分:0)
$this->db->select('*');
$this->db->from('tb_institutional_profile');
$this->db->order_by('tb_institutional_profile.institution_name','ASC');
$query = $this->db->get();
$res = $query->result();
$totalRows_Institutions = $query->num_rows()
$result = "<td width='192'>";
$result .= "<select name='institution_id'>";
foreach ($query->result() as $row) {
$result .="<option value='".$row->institution_id."'>'".$row->institution_name."'</option>'";
}
$result .= "</select>";
$result .= "</td>";
return $result;