阅读时无法在 codeigniter 中显示项目。显示致命错误
Not being able to dispaly items in codeigniter while reading .It is showing fatal error
这里的 pname[] 是输入的名称,database.It 中的列显示我不能包含
阅读那些方括号 records.so 我该如何解决这个问题?我不能将输入名称更改为
它是 array.if 我更改名称然后它不会存储数组 values.help 我解决这个错误
因为我无法进入项目
<!-- end snippet -->
<table class="table table-type " style="text-align:center">
<thead>
<tr>
<th scope="col">Booking ID</th>
<th scope="col">Train ID</th>
<th scope="col">Booked By</th>
<th scope="col">Passengers</th>
<th scope="col">Origin</th>
<th scope="col">Destination</th>
<th scope="col">Date</th>
<th scope="col">Arrival Time</th>
<th scope="col">Departure Time</th>
<th scope="col">Class</th>
<th scope="col">Paid</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php if(count($booked)):?>
<?php foreach($booked as $book): ?>
<tr class="table-type">
<td><?php echo $book->booking_id; ?></td>
<td><?php echo $book->train_id; ?></td>
<td><?php echo $book->booked_by; ?></td>
<td><?php echo $book->pname[]; ?></td>
<td><?php echo $book->origin; ?></td>
<td><?php echo $book->destination; ?></td>
<td><?php echo $book->date; ?></td>
<td><?php echo $book->arrivaltime; ?></td>
<td><?php echo $book->departuretime; ?></td>
<td><?php echo $book->class; ?></td>
<td><b><?php echo $book->tamount; ?></b> by <?php echo $book->cardtype; ?> Card</td>
<td>
<?php echo anchor("admin/deletetrain/{$book->train_id}",'Delete',['class'=>'btn btn-outline- danger','style'=>'font-size:15px;height:20px;width:40%;padding-top :0px;']); ?>
</td>
</tr>
<?php endforeach;?>
<?php else:?>
<tr>
<td></td>
<td></td>
<td></td>
<td><h4>NO Trains Available!!</h4></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php endif;?>
</tbody>
控制器
public function reserve_train($train_id)
{
$this->load->model('user_model');
$this->form_validation->set_rules('passenger_id', 'Passenger ID', 'required');
$this->form_validation->set_rules('booked_by', 'Booked by', 'required');
$this->form_validation->set_rules('pname[]', 'Passenger Name', 'required');
$this->form_validation->set_rules('age[]', 'Age', 'required');
$this->form_validation->set_rules('gender[]', 'Gender', 'required');
$this->form_validation->set_rules('train_id', 'Train ID', 'required');
$this->form_validation->set_rules('origin', 'Origin', 'required');
$this->form_validation->set_rules('destination', 'Destination', 'required');
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('arrivaltime', 'ArrivalTime', 'required');
$this->form_validation->set_rules('departuretime', 'DepartureTime', 'required');
$this->form_validation->set_rules('class', 'Class', 'required');
$this->form_validation->set_rules('price', 'Price', 'required');
$this->form_validation->set_rules('ano', 'No.of Adults', 'required|max_length[1]');
$this->form_validation->set_rules('cno', 'No.of Children', 'required|max_length[1]');
$this->form_validation->set_rules('tamount', 'Total Amount', 'required');
$this->form_validation->set_rules('cardno', 'Card Number', 'required|min_length[16]|max_length[16]');
$this->form_validation->set_rules('noc', 'Name on card', 'required|trim|alpha_numeric_spaces');
$this->form_validation->set_rules('month', 'Month', 'required');
$this->form_validation->set_rules('year', 'Year', 'required');
$this->form_validation->set_rules('cardtype', 'Card Type', 'required');
$this->form_validation->set_rules('cvv', 'CVV', 'required|min_length[3]|max_length[3]');
$this->form_validation->set_error_delimiters('<p class="text-danger">','</p>');
$data=$this->user_model->fetchdata($this->session->userdata('passenger_id'));
if($this->form_validation->run()){
// $data=$this->input->post();
//if($this->input->post()){
$pname=implode(", ", $this->input->post('pname[]'));
$age=implode(", ", $this->input->post('age[]'));
$gender=implode(",", $this->input->post('gender[]'));
$data= array(
'passenger_id'=>$this->input->post('passenger_id'),
'booked_by'=>$this->input->post('booked_by'),
'pname[]'=> $pname ,
'age[]'=>$age ,
'gender[]'=> $gender,
'train_id'=>$this->input->post('train_id'),
'origin'=>$this->input->post('origin'),
'destination'=>$this->input->post('destination'),
'date'=>$this->input->post('date'),
'arrivaltime'=>$this->input->post('arrivaltime'),
'departuretime'=>$this->input->post('departuretime'),
'class'=>$this->input->post('class'),
'price'=>$this->input->post('price'),
'ano'=>$this->input->post('ano'),
'cno'=>$this->input->post('cno'),
'tamount'=>$this->input->post('tamount'),
'cardno'=>$this->input->post('cardno'),
'noc'=>$this->input->post('noc'),
'month'=>$this->input->post('month'),
'year'=>$this->input->post('year'),
'cardtype'=>$this->input->post('cardtype'),
'cvv'=>sha1($this->input->post('cvv')),
);
$this->load->model('user_model');
if($this->user_model->reserve($data,$train_id)){
$this->session->set_flashdata('message','Train booked successfully');
return redirect("user/ticket");
}
else{
$this->session->set_flashdata('message','Failed to Book Train');
}return redirect("user/reserve/{$train_id}");
}else{
$this->reserve($train_id);
}
}
Here is the view image
好的,所以在看到您的代码后,我认为您的数据已正确保存,但您无法检索它。
<?php $book->pname; /* This should work for you because you're getting the object that is the name of the table column not pname[]. */ ?>
但是如果想做一些奇特的事情,比如在列表中一个一个地显示它们,那么您必须将数据转换回数组以检索它,因为它最初是数组,然后遍历它的元素和echo
他们一个一个。
<?php
$pnameArr = explode(', ', $book->pname); // array
?>
<ul>
<?php
foreach($pnameArr as $pnameSingle){ // traverse all its elements
echo "<li>{$pnameSingle}</li>";
}
?>
</ul>
希望对您有所帮助。
在 foreach($booked as $book):
行后写 echo '<pre>'; print_r($book)
通过这样做你可以检查 pname 格式。这将帮助您以正确的方式显示 pname
这里的 pname[] 是输入的名称,database.It 中的列显示我不能包含 阅读那些方括号 records.so 我该如何解决这个问题?我不能将输入名称更改为 它是 array.if 我更改名称然后它不会存储数组 values.help 我解决这个错误 因为我无法进入项目
<!-- end snippet -->
<table class="table table-type " style="text-align:center">
<thead>
<tr>
<th scope="col">Booking ID</th>
<th scope="col">Train ID</th>
<th scope="col">Booked By</th>
<th scope="col">Passengers</th>
<th scope="col">Origin</th>
<th scope="col">Destination</th>
<th scope="col">Date</th>
<th scope="col">Arrival Time</th>
<th scope="col">Departure Time</th>
<th scope="col">Class</th>
<th scope="col">Paid</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php if(count($booked)):?>
<?php foreach($booked as $book): ?>
<tr class="table-type">
<td><?php echo $book->booking_id; ?></td>
<td><?php echo $book->train_id; ?></td>
<td><?php echo $book->booked_by; ?></td>
<td><?php echo $book->pname[]; ?></td>
<td><?php echo $book->origin; ?></td>
<td><?php echo $book->destination; ?></td>
<td><?php echo $book->date; ?></td>
<td><?php echo $book->arrivaltime; ?></td>
<td><?php echo $book->departuretime; ?></td>
<td><?php echo $book->class; ?></td>
<td><b><?php echo $book->tamount; ?></b> by <?php echo $book->cardtype; ?> Card</td>
<td>
<?php echo anchor("admin/deletetrain/{$book->train_id}",'Delete',['class'=>'btn btn-outline- danger','style'=>'font-size:15px;height:20px;width:40%;padding-top :0px;']); ?>
</td>
</tr>
<?php endforeach;?>
<?php else:?>
<tr>
<td></td>
<td></td>
<td></td>
<td><h4>NO Trains Available!!</h4></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php endif;?>
</tbody>
控制器
public function reserve_train($train_id)
{
$this->load->model('user_model');
$this->form_validation->set_rules('passenger_id', 'Passenger ID', 'required');
$this->form_validation->set_rules('booked_by', 'Booked by', 'required');
$this->form_validation->set_rules('pname[]', 'Passenger Name', 'required');
$this->form_validation->set_rules('age[]', 'Age', 'required');
$this->form_validation->set_rules('gender[]', 'Gender', 'required');
$this->form_validation->set_rules('train_id', 'Train ID', 'required');
$this->form_validation->set_rules('origin', 'Origin', 'required');
$this->form_validation->set_rules('destination', 'Destination', 'required');
$this->form_validation->set_rules('date', 'Date', 'required');
$this->form_validation->set_rules('arrivaltime', 'ArrivalTime', 'required');
$this->form_validation->set_rules('departuretime', 'DepartureTime', 'required');
$this->form_validation->set_rules('class', 'Class', 'required');
$this->form_validation->set_rules('price', 'Price', 'required');
$this->form_validation->set_rules('ano', 'No.of Adults', 'required|max_length[1]');
$this->form_validation->set_rules('cno', 'No.of Children', 'required|max_length[1]');
$this->form_validation->set_rules('tamount', 'Total Amount', 'required');
$this->form_validation->set_rules('cardno', 'Card Number', 'required|min_length[16]|max_length[16]');
$this->form_validation->set_rules('noc', 'Name on card', 'required|trim|alpha_numeric_spaces');
$this->form_validation->set_rules('month', 'Month', 'required');
$this->form_validation->set_rules('year', 'Year', 'required');
$this->form_validation->set_rules('cardtype', 'Card Type', 'required');
$this->form_validation->set_rules('cvv', 'CVV', 'required|min_length[3]|max_length[3]');
$this->form_validation->set_error_delimiters('<p class="text-danger">','</p>');
$data=$this->user_model->fetchdata($this->session->userdata('passenger_id'));
if($this->form_validation->run()){
// $data=$this->input->post();
//if($this->input->post()){
$pname=implode(", ", $this->input->post('pname[]'));
$age=implode(", ", $this->input->post('age[]'));
$gender=implode(",", $this->input->post('gender[]'));
$data= array(
'passenger_id'=>$this->input->post('passenger_id'),
'booked_by'=>$this->input->post('booked_by'),
'pname[]'=> $pname ,
'age[]'=>$age ,
'gender[]'=> $gender,
'train_id'=>$this->input->post('train_id'),
'origin'=>$this->input->post('origin'),
'destination'=>$this->input->post('destination'),
'date'=>$this->input->post('date'),
'arrivaltime'=>$this->input->post('arrivaltime'),
'departuretime'=>$this->input->post('departuretime'),
'class'=>$this->input->post('class'),
'price'=>$this->input->post('price'),
'ano'=>$this->input->post('ano'),
'cno'=>$this->input->post('cno'),
'tamount'=>$this->input->post('tamount'),
'cardno'=>$this->input->post('cardno'),
'noc'=>$this->input->post('noc'),
'month'=>$this->input->post('month'),
'year'=>$this->input->post('year'),
'cardtype'=>$this->input->post('cardtype'),
'cvv'=>sha1($this->input->post('cvv')),
);
$this->load->model('user_model');
if($this->user_model->reserve($data,$train_id)){
$this->session->set_flashdata('message','Train booked successfully');
return redirect("user/ticket");
}
else{
$this->session->set_flashdata('message','Failed to Book Train');
}return redirect("user/reserve/{$train_id}");
}else{
$this->reserve($train_id);
}
}
Here is the view image
好的,所以在看到您的代码后,我认为您的数据已正确保存,但您无法检索它。
<?php $book->pname; /* This should work for you because you're getting the object that is the name of the table column not pname[]. */ ?>
但是如果想做一些奇特的事情,比如在列表中一个一个地显示它们,那么您必须将数据转换回数组以检索它,因为它最初是数组,然后遍历它的元素和echo
他们一个一个。
<?php
$pnameArr = explode(', ', $book->pname); // array
?>
<ul>
<?php
foreach($pnameArr as $pnameSingle){ // traverse all its elements
echo "<li>{$pnameSingle}</li>";
}
?>
</ul>
希望对您有所帮助。
在 foreach($booked as $book):
行后写 echo '<pre>'; print_r($book)
通过这样做你可以检查 pname 格式。这将帮助您以正确的方式显示 pname