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.
Related
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
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();
}
How can I use Distinct with join in CodeIgniter, I'm trying to fetch customer's name and registered category, but my problem is whiles fetching the data I'm getting data in repetation because of sub-category, I've used distinct but then I'm getting Ambiguous field error, how can I solve this problem.
My View
<table class="table table-hover example1">
<thead>
<tr>
<th>SNo.</th>
<th>Business Name</th>
<th>Category Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php $i=0;
foreach($value as $row){ ?>
<tr>
<td><?php echo ++$i;?></td>
<td><?php echo $row->Bussiness_Name;?></td>
<td><?php echo $row->Category_Name;?></td>
<td onClick="RestoreVendor(<?php echo $row->Business_Id; ?>,<?php echo $row->Trash;?>,'<?php echo $row->Bussiness_Name;?>')" class="btn btn-primary">Remove</td>
</tr>
<?php }?>
</tbody>
</table>
My Controller:
public function removecategory()
{
$this->load->model('VendorModel');
$data = $this->VendorModel->remove_category();
$this->load->view('admin/remove_cat', array('value'=>$data));
}
My Model
public function remove_category()
{
$this->db->select('*');
$this->db->distinct('Category_Id');
$this->db->from('business_mapping');
$this->db->join('business_profile_details', 'business_profile_details.Business_Id = business_mapping.Business_Id');
$this->db->join('category_master', 'category_master.Category_Id = business_mapping.Category_Id');
$query = $this->db->get();
return $query->result();
}
result image
You can use below mentioned query.
$query = $this->db->group_by('category_master.Category_Id,business_profile_details.Business_Id');
Please try above, It will help you.
you can use
$this->db->distinct();
Some times distinct not works then you can use
$this->db->group_by('business_mapping.unique_coloumn_Name');
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>
So... HTML is still giving me a hard time. I have some code that prints out a report of the order for each member, which must be printed as we hand them out to the people delivering the orders. The problem is that the div which contains the page break is a whole bunch of odd sizes, so when I try to print off the report the formatting is very odd. This sometimes results in blank pages being printed, or having an order split between the bottom and top of two different pages.
I would like to figure out how to get each order to print on its own page, right at the top of the page, but that last div is not working the way I want it to. I have been trying off and on to fix this for weeks; can someone help me?
Here is the code for the page:
<style>
.first-time{
text-align: right;
color:#fff;
background: #a00;
}
.page-break {
display: block;
page-break-before: always;
}
.title th{
background: #6c6c6c;
color:#fff
}
</style>
<script>
</script>
<div class="reports">
<table cellpadding="0" cellspacing="0">
<?php $count_orders = 0 ?>
<?php $count_products = 0 ?>
<?php foreach ($sites as $site): ?>
<tr>
<th class="big" colspan="7"><?php echo $site ?></th>
</tr>
<?php foreach ($orders as $page_number => $order): ?>
<?php if ($order['Site']['name'] == $site): ?>
<tr class="title">
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>City</th>
<th>Email</th>
<th>Phone</th>
<th>Site</th>
</tr>
<tr>
<td><strong><?php echo $order['Account']['first_name'] ?></strong></td>
<td><strong><?php echo $order['Account']['last_name'] ?> <span style="color:red"><?php echo ($order['Account']['homebound'] == 1)?'(homebound)':'';?></span></strong></td>
<td><?php echo $order['Account']['street1'].$order['Account']['street2'] ?></td>
<td><?php echo $order['Account']['city']?></td>
<td><?php echo $order['Account']['email'] ?></td>
<td><?php echo $order['Account']['phone'] ?></td>
<td><?php echo $order['Site']['name'] ?></td>
</tr>
<tr>
<th colspan="6">Product</th>
<th>Quantity</th>
</tr>
<?php foreach ($order['ProductType'] as $productType): ?>
<tr>
<td colspan="6"><?php echo $productType['type'] ?></td>
<td><?php echo $productType['OrdersProductType']['quantity']*$productType['units'] ?></td>
</tr>
<?php $count_products++ ?>
<?php endforeach ?>
<?php foreach ($order['Coupon'] as $coupon): ?>
<tr>
<td colspan="6">Coupon</td>
<td>-<?php echo $coupon['discount'] ?></td>
</tr>
<?php endforeach ?>
<?php $count_orders++ ?>
<input class='account-id' href='/Reports/firstTime' data-sale="<?php echo $order['Order']['sale_id'] ?>" type='hidden' name='data[Account][id]' value="<?= $order['Account']['id'] ?>" />
<tr></tr>
<tr><td style='border:none; padding:0;'><div class='page-break'></div></td></tr>
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>
</table>
Most of that can probably be ignored, but I included it just in case since my HTML coding experience is minimal at best. I'm mostly a back-end programmer, but the people using this report don't understand the difference and don't get why I can't just fix it by adding a page break like in Word...
I think you want to use
.page-break {
display: block;
page-break-after: always;
}
so it breaks the page after every order not right before that div. I could be wrong though try it and let me know
I'm going to go ahead and close this question. After talking with my other programmer, we haven't found exactly the root cause of the problem, but we worked around it by separating the table into two tables, one of which was just for the page break.
This is, we know, terrible coding style. However, it fixed the problem, which leads us to believe that something is grabbing padding from the tables and adding it after the page break. I wasn't able to find what it was, but splitting it fixed it.
So... bad coding, but it got it fixed. For our little company, that is good enough. Thank you for the help.