带有where子句的get_select_option函数

时间:2015-06-03 04:40:45

标签: php mysql codeigniter

我是php的新手我需要帮助 我想在这里添加where子句' get_select_option'

我的get_select_option代码在这里



function get_select_option($table,$id,$name,$selected=0){
		$query = $this->db->get($table);
		$select = '<option value="">SELECT</option>';
		if($query->num_rows()>0){
			foreach($query->result_array() as $row){
			$selected_option = ($selected==$row[$id]) ? ' selected="selected" ':' ';
				$select.='<option value="'.$row[$id].'" '. $selected_option.'>'.trim(strtoupper($row[$name])).'</option>';
			}
		}
		return $select;
	}
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

在Codeigniter中,您可以使用where设置$this->db->where();子句。代码将是 -

$this->db->where('fieldname', 'valuetomatch');
$query = $this->db->get($table);

答案 1 :(得分:0)

<p id="notice"><%= notice %></p> <h1>Listing Users</h1> <table> <thead> <tr> <th>Name</th> <th colspan="3"></th> </tr> </thead> <tbody> <% @users.each do |user| %> <tr> <td><%= user.name %></td> <td><%= link_to 'Show', user %></td> <td><%= link_to 'Edit', edit_user_path(user) %></td> <td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> </table> <br> <%= link_to 'New User', new_user_path %> 声明

上方的以下函数中使用此行$this->db->where('column_name','your_value');
$query = $this->db->get($table);