2

このコードを受け入れ可能な 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>
4

2 に答える 2

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>
于 2012-10-09T09:45:07.413 に答える
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;
于 2012-10-09T09:36:17.577 に答える