how to display ticket where i want data from booking page in codeigniter - mysql

In the previous page i filled payment details and submited and it shows train booked and i want to print ticket but im not getting data of the present booking .i tried to get data with booking_id but its not retrieving data.i can get retrieve data with passenger_id but it is not unique bcz one user can book multiple trains so it shows first entry in the database if there are multiple entries by one passenger .but im not being to get data with booking_id.help me!!!!!!
model
public function viewtrain($booking_id=null)
{
if($booking_id)
{
$this->db->select('*');
$this->db->from('booked');
$this->db->where('booking_id=?');
$alltrains=$this->db->get();
return $alltrains->result();
}
}
view
<table class="table table-type " style="text-align:center">
<thead>
<tr>
<th scope="col">Train ID</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">Price</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php if(count($alltrains)):?>
<?php foreach($alltrains as $alltrain): ?>
<tr class="table-type">
<td><?php echo $alltrain->booking_id; ?></td>
<td><?php echo $alltrain->origin; ?></td>
<td><?php echo $alltrain->destination; ?></td>
<td><?php echo $alltrain->date; ?></td>
<td><?php echo $alltrain->arrivaltime; ?></td>
<td><?php echo $alltrain->departuretime; ?></td>
<td><?php echo $alltrain->class; ?></td>
<td><?php echo $alltrain->price; ?></td>
<td>
<?php echo anchor("admin/edittrain/{$alltrain->train_id}",'Edit',['class'=>'btn btn-outline-primary','style'=>'font-size:15px;height:20px;width:40%;padding-top :0px;']); ?>
<?php echo anchor("admin/deletetrain/{$alltrain->train_id}",'Delete',['class'=>'btn btn-outline-danger','style'=>'font-size:15px;height:20px;width:50%;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>
</table>
Controller
public function ticket($booking_id=null)
{
$this->load->model('user_model');
$alltrains=$this->user_model->viewtrain($booking_id);
$this->load->view('ticket',['alltrains'=>$alltrains]);
}

The data is not being retrieved because the format is wrong in your model, I've written the correct format below, see if this helps you.
Model
if($booking_id)
{
$this->db->select('*');
$this->db->from('booked');
$this->db->where('booking_id', $booking_id);
$alltrains=$this->db->get();
return $alltrains->result();
}

Related

How do you get stats on a gmod darkrp server to display it on a website/

I want to display some stats in a website like this:
https://zarpgaming.com/index.php/leaderboards/darkrp/gangs
how do I do this ? I work mostly with front end so I don't really know where to start.
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Salary</th>
<th>Wallet</th>
</tr>
</thead>
<tbody>
<?php
$conn = mysqli_connect("yourip","username","pw","databasename");
$result = mysqli_query($conn, "SELECT * FROM tablename");
while ($row = mysqli_fetch_assoc($result)):
?>
<tr>
<td><?php echo $row['rpname']; ?></td>
<td><?php echo $row['salary']; ?></td>
<td><?php echo $row['wallet']; ?></td>
<?php endwhile; ?>
</tr>
</tbody>
</table>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.13.1/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.6.0/dt-1.13.1/datatables.min.js"></script>
<script>
$(".table").DataTable();
</script>
this code works
got it from this video
https://www.youtube.com/watch?v=UN_BO_qlna8

Not being able to dispaly items in codeigniter while reading .It is showing fatal error

Here pname[] is the name of input and column in the database.It is showing that i cant include
square brackets in reading those records.so how can i solve this?i cant change the name of input as
it is array.if i change the name then it wont store array values.help me in solving this error
beacuase im not getting able to move into the project
<!-- 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>
COntroller
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
Write echo '<pre>'; print_r($book) after the line foreach($booked as $book): by doing this you can check pname format . This will help you to display pname in proper way
Ok, so after seeing your code, I think your data is being saved properly but you're having trouble retrieving it.
<?php $book->pname; /* This should work for you because you're getting the object that is the name of the table column not pname[]. */ ?>
But if want to do something fancy, say display them one by one in a list then you'll have to convert the data back into an array to retrieve it as it was initially array, then loop through its element and echo them one by one.
<?php
$pnameArr = explode(', ', $book->pname); // array
?>
<ul>
<?php
foreach($pnameArr as $pnameSingle){ // traverse all its elements
echo "<li>{$pnameSingle}</li>";
}
?>
</ul>
Hope this helps you.

Adding Borders to HTML Table of SQL Query Results

Trying to add borders and column headings to a table of results from an SQL query.
The results display fine however there are no headings or borders on the table, so it just looks like a jumble of results.
</div>
<div id="section">
<h2>Upcoming Events</h2>
<?php
$connection = mysqli_connect('localhost', 'c3437691', 'chelsea27', 'c3437691');
?>
<?php
$query = "SELECT * FROM Event";
$result=mysqli_query($connection, $query);
echo "<table>";
while ($row=mysqli_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['Event_Name']?></td>
<td><?php echo $row['Event_Location']?></td>
<td><?php echo $row['Event_Date']?></td>
<td><?php echo $row['Ticket_Price']?></td>
<td><?php echo $row['Ticket_Stock']?></td>
</tr>
<?php
}
?>
</div>
You need to explicitly output your table headers -- simply iterating over results from mysql will not include column names.
After your opening <table> but before your while loop, add the following:
<tr>
<th>Event Name</th>
<th>Event Location</th>
<th>Event Date</th>
<th>Ticket Price</th>
<th>Ticket Stock</th>
</tr>
If you want to add borders to the table, you should apply CSS to the table.

php host status from php mysql database

Help me!!
Seem when i run the scripts, the output seems wrong :(
This is the output...
Here My Output
The 1st and 3rd entry is true, online
But the rest should be OFFLINE but the output shows all ONLINE
I think the problem is from foreach loop but I cannot figure out how to solve the problem
Please help me... :(
<table border="1">
<thead>
<tr>
<th>Entry</th>
<th>Host</th>
<th>Name</th>
<th>Location</th>
<th>Description</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM host_entry";
$no = 1;
//foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row)
$dbhi = $dbh->query($sql);
foreach ($dbhi->fetchAll(PDO::FETCH_BOTH) as $data) {
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $data['host_server']; ?></td>
<td><?php echo $data['host_name']; ?></td>
<td><?php echo $data['host_location']; ?></td>
<td><?php echo $data['host_desc']; ?></td>
<td>
<?php
$ip = $data["host_server"];
// Run the ping to the IP
exec ("ping -n 1 -w 1 $ip", $ping_output);
if(preg_match("/Reply/i", $ping_output[2])!==0) {
echo "<font color='green'><strong>Online!</strong></font>";
}
else if(preg_match("/Reply/i", $ping_output[2])===0){
echo "<font color='red'><strong>Offline!</strong></font>";
}
?>
</td>
</tr>
<?php
}
?>
</tbody>

Multiple Headers Occur

This is supposed to be a simple high scores table. but everytime it pulls another player from the database it looks like this.
(table headers)
player
(table headers)
player
(table headers)
player
and so on you get the picture... I want it to just show the header one time at the top of the list of players... I had it working at one time and don't remember what I changed that caused it to do this, does anyone know how to fix it?
Here is my code:
<?php
$result = mysql_query("SELECT * FROM users ORDER BY explores DESC LIMIT 20;")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
?>
<table class="reg-box" style="width: 600px; text-align: center;" align="center" cellspacing="5">
<tbody>
<tr>
<th colspan="2">Trainer</th>
<th colspan="2">Explores</th>
</tr>
<tr>
<td colspan="2"><?php echo "".$row['username'].""; ?></td>
<td colspan="2"> <?php echo $row['explores']; ?></td>
</tr>
</tbody>
</table>
<?php } ?>
The problem with your code was the table is getting created in the loop, leading to the multiple headers. Instead remove the creation of the table from the while loop and then try to update all the result set you get from the query you fired in a loop. Try this.
$result = mysql_query("SELECT * FROM users ORDER BY explores DESC LIMIT 20;")
or die(mysql_error());
?>
<table class="reg-box" style="width: 600px; text-align: center;" align="center" cellspacing="5">
<tbody>
<tr>
<th colspan="2">Trainer</th>
<th colspan="2">Explores</th>
</tr>
<?php
while($row = mysql_fetch_array( $result )) {
<tr>
<td colspan="2"><?php echo "".$row['username'].""; ?></td>
<td colspan="2"> <?php echo $row['explores']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>