|
楼主 |
发表于 2012-3-3 13:10:12
|
显示全部楼层
本帖最后由 leeloo 于 2012-3-3 13:28 编辑
明白了。
words_model.php
<?php
class Words_model extends CI_Model {
public function __construct()
{
$this->load->database(); //载入数据库
}
public function get_words($zimu) //查询词
{
$query = $this->db->query("SELECT * FROM test WHERE letters = '$zimu';");
return $query->result_array();
}
public function get_relation_mots($zimu) //查询关联词
{
$query = $this->db->query("SELECT mot_2 FROM relation WHERE mot_1 = '$zimu';");
return $query->result_array();
}
}
words_db.php
<?php
class Words_db extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('words_model');
}
public function index()
{
$data['words'] = $this->words_model->get_words('AAA');
$data['title'] = 'Words';
$data['relation_mots'] = $this->words_model->get_relation_mots('AAA');
$counter = 0;
foreach ($data['relation_mots'] as $relation_mots_item):
{
$data['relation_mots_id2'][$counter] = $this->words_model->get_words($relation_mots_item['mot_2']);
$counter = $counter+1;
}
endforeach;
$data['counter'] = $counter;
$this->load->view('templates/header', $data);
$this->load->view('words_db/index', $data);
$this->load->view('templates/footer');
}
}
index.php
<?php foreach ($words as $words_item): ?>
<h2><?php echo $words_item['id'] ?>, <?php echo $words_item['letters'] ?></h2>
<p><a href="words_db/<?php echo $words_item['letters'] ?>">View article</a></p>
<?php endforeach ?>
<?php foreach ($relation_mots as $relation_mots_item):?>
<h2>Relation Mots: <?php echo $relation_mots_item['mot_2'] ?></h2>
<p><a href="words_db/<?php echo $relation_mots_item['mot_2'] ?>">Relation Mots</a></p>
<?php endforeach ?>
<?php
for ($relation_mots_id_counter=0; $relation_mots_id_counter<$counter; $relation_mots_id_counter++)
{
echo $relation_mots_id2[$relation_mots_id_counter]['id'];
}
?> |
|