php - 将 mysql 代码转换为 codeigniter

标签 php mysql codeigniter

如何将此代码转换为可接受的 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>

最佳答案

首先,在application/config/ 文件夹中正确设置您的database.php,然后自动加载或使用$this->load->database( ); 在你的 Controller /模型上

<?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>

关于php - 将 mysql 代码转换为 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12796936/

相关文章:

php - 为什么人们不使用序号来存储图像?

PHP INSERT INTO 不起作用,没有错误

mysql - 有人让 Ruby 与 MySQL 5.1 一起工作吗?

mysql - 试图攻击mysql?

mysql - Codeigniter 上使用数组和 MySQL 的动态菜单出现问题

php - Codeigniter: header 已发送错误

javascript - 如何隐藏轮播中单个图像的下一个和上一个按钮?

php - 上传多个文件到服务器和

php adodb StartTrans() 不工作?

php - 查找预订交叉日期(入住、退房)或每个房间 ID 的相同日期