如何从codeigniter中的连接表中读取多个值
这是model.php
<table class="table table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="col-sm-1" >VILLAGE</th>
<th class="col-sm-1" >ZONE</th>
<th class="col-sm-1" >SCHOOL</th>
</tr>
</thead>
<tbody>
<?php if (!empty($all_village_info)):
foreach ($all_village_info as $v_village) :
?>
<tr>
<td><?php echo $v_village->village_name ?></td>
<td><?php echo $v_village->zone_name ?></td>
<td><?php echo $v_village->school_name ?></td>
</tr>
<?php
endforeach;
?>
<?php endif; ?>
</tbody>
</table>
这是view.php
|-------------|------------|
|village_name |school_id |
|-------------|------------|
|Bhiwani |1,2,3 |
sql_is中的值
|-------------|------------|
|Village |School |
|-------------|------------|
|Bhiwani |School 1 |
视图为
|-------------|-------------------------------|
|Village |School |
|-------------|-------------------------------|
|Bhiwani |School 1, School 2, School 3 |
我想表现出像
SecurityModule.forRoot(new SecurityMockService())
我该怎么做?帮助PLZ 如何从codeigniter中的连接表中读取多个值
答案 0 :(得分:0)
您可以使用表格的别名,然后选择那些
注意:我强烈建议您使用*当且仅当您使用其他所有列时,它才会使您的查询位置变慢。
/ *你可以为表取一个别名并从中选择*,我遵循链接方法。 * /
Number 1: <input type="text" placeholder="Number 1" id="value1" name="value1" /><br>
Number 2: <input type="text" placeholder="Number 2" id="value2" name="value2" />
<select id="user_select">
<option value="+" selected="selected">Addition</option>
<option value="/">Division</option>
<option value="*">Multiplication</option>
</select> <input type="button" name="Sumbit" value="Calculate" onclick="calculate()" /><br>
Result: <input type="text" id="answer" name="answer" value="Your Answer" />
答案 1 :(得分:0)
您可以针对您的问题尝试此解决方案:
请更改您的模态功能:
all_village_info:
public function all_village_info($id = NULL) {
$this->db->select('tbl_village.*', FALSE);
$this->db->select('GROUP_CONCAT(tbl_school.school_name ORDER BY tbl_school.school_id) as school_name', FALSE);
$this->db->from('tbl_village');
$this->db->join('tbl_school', 'FIND_IN_SET(tbl_school.school_id, tbl_village.school_id) > 0', 'left');
if (!empty($id)) {
$this->db->where('tbl_village.village_id', $id);
$query_result = $this->db->get();
$result = $query_result->row();
} else {
$query_result = $this->db->get();
$result = $query_result->result();
}
return $result;
}
我希望它会对你有所帮助。