我使用Codeigniter开发了自己的基于Web的图书馆系统。我对活动记录感到困惑。为明确目的,请参阅下面的代码:
//Add Publisher Form
<form action="<?php echo base_url(); ?>admin/addPublisher" method="post" class="form-horizontal" role="form">
<div class="col-lg-12">
<div class="row">
<div class="form-group">
<label for="penerbit" class="col-lg-2 control-label">Publisher</label>
<div class="col-lg-9">
<input type="text" name="publisher" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="website" class="col-lg-2 control-label">Website</label>
<div class="col-lg-9">
<input type="text" name="website" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="email" class="col-lg-2 control-label">Contact</label>
<div class="col-lg-9">
<input type="text" name="phone" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="telepon" class="col-lg-2 control-label">E-mail</label>
<div class="col-lg-9">
<input type="text" name="email" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="alamat" class="col-lg-2 control-label">Address</label>
<div class="col-lg-9">
<textarea name="address" class="form-control" rows="5"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="" class="col-lg-2"></label>
<div class="col-lg-9">
<button type="submit" class="btn btn-success">Add Publisher</button>
</div>
</div>
</div>
</div>
</form>
// Add Publisher @ Admin Controller
public function addPublisher()
{
if($this->session->userdata('logged_in'))
{
$publisher = $this->input->post('publisher');
$web = $this->input->post('website');
$email = $this->input->post('email');
$phone = $this->input->post('phone');
$addr = $this->input->post('address');
if(!empty($publisher) && !empty($web) && !empty($email) && !empty($phone) && !empty($addr)){
$this->adminModel->insertPublisher($publisher, $web, $email, $phone, $addr);
redirect ('admin/publisher');
} else {
redirect ('admin/publisher');
}
$session_data = $this->session->userdata('logged_in');
$data['user'] = $session_data['user'];
$data['pubs'] = $this->adminModel->getAllPublisher();
$data['tittle'] = "Add Publisher Page";
$this->load->view('admin/static/header', $data);
$this->load->view('admin/static/header-nav');
$this->load->view('admin/static/left-nav');
$this->load->view('admin/publisher/publisher', $data);
} else {
$this->index();
}
}
// Here my adminModel for inserting records
public function insertPublisher($publisher, $web, $phone, $email, $address)
{
$query = $this->db->query("INSERT INTO publisher (`id_publisher`, `publiser`, `website`, `phone`, `email`, `address`, `created_at`) VALUES ('', '$publisher', '$web', '$phone', '$email', '$address', NOW())");
return $query;
}
// The output in print_r()
stdClass Object
(
[id_publisher] => 1
[publisher] => Example Publishing
[website] => example.com
[phone] => mypublisher@local <--- this is my point
[email] => 1234567 <--- and this is
[address] => asdfgj
[create_at] => 2014-04-30 10:48:08
)
我的问题是:
非常感谢您的建议。
答案 0 :(得分:1)
检查你的代码 改变这个
$this->adminModel->insertPublisher($publisher, $web, $email, $phone, $addr);
^ ^
redirect ('admin/publisher');
到这个
$this->adminModel->insertPublisher($publisher, $web, $phone,$email, $addr);
redirect ('admin/publisher');
并检查您的模型
public function insertPublisher($publisher, $web, $phone, $email, $address)
{
$query = $this->db->query("INSERT INTO publisher (`id_publisher`, `publiser`, `website`, `phone`, `email`, `address`, `created_at`) VALUES ('', '$publisher', '$web', '$phone', '$email', '$address', NOW())");
return $query;
}
从您使用此查询的数据中检索数据时的第二个问题
"select * from publisher ORDER BY publiser ASC"
您可以按升序排序
按字母顺序获取发布商名称答案 1 :(得分:0)
您需要更加具体地了解您在&#39; print_r()&#39;中打印的变量,是否在插入数据库后将其打印出来?
据我了解你的问题,原因是数据库中字段的顺序。