Page breaks in HTML - html

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.

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

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>

WordPress - Display Post Content and Post Meta on a Page in the Admin Area

I am trying to create a page in my WordPress Admin Area that displays excerpts of posts and various custom field meta in a table-style layout.
If this were a front-end WordPress Template, I could do this very easily using a WordPress Loop and Query, however, I am not so sure how I would go about doing this on a page in the admin area.
Would it be the same, or would I need to use a completely new method? If so, could someone please provide a working example of how I would do this?
The admin page will be created using an included file within my functions.php - or at least that is the plan at the moment, so I just need help in figuring out how to pull the WordPress Excerpts and Post Meta.
you can use the WP_Query object everytime after WordPress is initialized, so if you like you can even make thousands of nested queries in den WordPress backend if you want to do this.
This is the way to go:
Create an action to add your backend page - write a Plugin or put it into your functions.php
Setup the Menu Page - the code is an example for a full backend administration Page of your Theme
Include your queries using the WP_Query object - optionally make database queries directly (http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query). Possibly use the "widefat" class of WordPress, for pretty formatting.
Make sure that your changes are saved correctly
add_action('admin_menu', 'cis_create_menu');
function cis_create_menu() {
//create new top-level menu
add_menu_page(__('Theme Settings Page',TEXTDOMAIN),__('Configure Theme',TEXTDOMAIN), 'administrator', __FILE__, 'cis_settings_page', '');
//call register settings function
add_action('admin_init','cis_register_settings');
}
function cis_register_settings() {
register_setting('cis-settings-group','cis_options_1','cis_validate_settings');
}
function cis_settings_page() {
// All Text field settings
$op_fields = array(
array(__('Label 1','textdomain'),"Description 1")
);
?>
<div class="wrap">
<h2><?php echo THEME_NAME; _e(": Settings",TEXTDOMAIN); ?></h2>
<?php
settings_errors();
?>
<form method="post" action="options.php">
<?php
settings_fields( 'cis-settings-group' );
$options = get_option('cis_options_1');
?>
<h3><?php _e('General','textdomain'); ?></h3>
<table class="widefat">
<thead>
<tr valign="top">
<th scope="row"><?php _e('Setting','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('Value','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('Description','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('ID','ultrasimpleshop'); ?></th>
</tr>
</thead>
<tbody>
<?php
// the text-settings we define fast display
$i=1;
foreach($op_fields as $op) {?>
<tr valign="top">
<td><label for="cis_oset_<?php echo $i; ?>"><?php echo $op[0]; ?></label></td>
<td><input size="100" id="cis_oset_<?php echo $i; ?>" name="cis_options_1[cis_oset_<?php echo $i; ?>]" type="text" value="<?php echo esc_attr($options['cis_oset_'.$i]);?>" /></td>
<td class="description"><?php echo $op[1]; ?></td>
<td class="description"><?php echo $i; ?></td>
</tr>
<?php
$i++;
} ?>
</tbody>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes',TEXTDOMAIN) ?>" />
</p>
</form>
</div>
<?php }
// Validate the user input - if nothing to validate, just return
function cis_validate_settings( $input ) {
$valid = array();
$i= 1;
while(isset($input['cis_oset_'.$i])) {
$valid['cis_oset_'.$i] = $input['cis_oset_'.$i];
$i++;
}
$cis_additional_settings = get_option('cis_options_1');
foreach($input as $ikey => $ivalue) {
if($ivalue != $valid[$ikey]) {
add_settings_error(
$ikey, // setting title
"cis_oset_".$ikey, // error ID
str_replace("%s",$ikey,__('Invalid Setting in Settings Area ("%s"). The value was not changed.',TEXTDOMAIN)), // error message
'error' // type of message
);
$valid[$ikey] = $cis_additional_settings[$ikey];
}
}
return $valid;
}
outside the loop you would need to use
$post->post_excerpt
or try this
function get_the_excerpt_here($post_id)
{
global $wpdb;
$query = "SELECT post_excerpt FROM $wpdb->posts WHERE ID = $post_id LIMIT 1";
$result = $wpdb->get_results($query, ARRAY_A);
return $result[0]['post_excerpt'];
}

How to display Serial Numbers with mysql query result?

I have a script that displays information of these fields- batchname, class, batchinstructor from the table "batch". But I want to display dynamically generated serial number on the left side when I show the data. For example:
Serial Number BatchName Class Batch Instructor
1. Solar Class Five John
2. Lunar Class six Bon Jovi
I have tried a lot but its not working. Would you please kindly help me to solve this? Please note that these serial number are not from database.
Here's my Controller:
<?php
class Batchlist extends CI_Controller{
function index(){
$this->load->library('pagination');
$config['base_url'] = base_url().'batchlist/index';
$config['total_rows'] = $this->db->get('batch')->num_rows();
$config['per_page'] = 20;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('mod_batchlist');
$data['records']= $this->mod_batchlist->batch_list($config['per_page'],$this->uri->segment(3));
$data['main_content']='view_batchlist';
$this->load->view('includes/template',$data);
}
}
?>
Here's my Model:
function batch_list($perPage,$uri) {
$this->db->select('*');
$this->db->from('batch');
$this->db->join('teacher', 'batch.batchinstructor = teacher.teacherid');
$this->db->order_by('batchid','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
Here's my View
<h1>Batch List </h1>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $row){ ?>
<tr>
<td><?php echo $row['batchname'];?></td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
Maybe I misunderstood, but...what about a simple counter?? (after you ordered your records in SQL).
You need to pass to the view the number of items per page (in this snippet: $per_page), then you retrieve the current page from the URI ($this->uri->segment(n)).
At page 1, counter starts from (20*0)+1, i.e. 1. At page 2, starts from (1*20)+1 ie 21, at page 3 from (2*20)+1 ie 41 and so on...
<?php
$cur_page = $this->uri->segment(n) ? intval($this->uri->segment(n)) : 1;
$i = (($cur_page-1) * $per_page) +1;
foreach ($records as $row) :
?>
<tr>
<td><?php echo $i;?>.</td>
<td><?php echo $row['batchname'];?></td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?>support/images/icons/edit.png" alt="Edit" /><img src="<?php echo base_url();?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php
++$i;
endforeach;
?>
You can place the counter wherever you want, I added a column for simplicity but if you want it somewhere else just place the counter there.
You said the serial numbers are not from the database. Where are they from then? If you want the database to generate them you can create a column named id and set it as the primary key and have it auto increment.