print all invoices - php

I am building an order system for a client and would like to give them the ability to print all invoices but i have no idea how to do it
the invoices will be stored in a mysql db and I would like display each invoice in a fresh page EG invoice.php?ID=234
but is it possible to print an array of pages?
I'm really stuck with this one so any ideas would be much appreciated.
Thanks for reading.
Im talking about printing to paper, through an actual printer.

There's a couple of ways you could do this:
1) Print a summary. Ok, maybe it's just me, but I HATE paper. I'd rather just have a table output of the important information and sent to the printer via Javascript.
2) Build a summary page in a loop, adding a CSS page break and then javascript-ing to the printer
3) Build a multi-page PDF.
My method for forcing user to printer: Open page in new window via action=_blank, then including this: <body onload="self.print()">
Here's a method to handle pagination on printers: How to deal with page breaks when printing a large HTML table

You could have the content of invoice.php be generated and import into your invoice report page using the include command:
$ID = 234;
include('invoice.php');
$ID = 235;
include('invoice.php');
$ID = 236;
include('invoice.php');
Obviously this would be a loop, not hard-coded. If there's a lot of invoices, you would probably only want to display a few at a time. Your invoice page would need to be coded to handle ID parameter from query string or variable.
invoice.php:
if (isset($_GET['ID']))
$ID = $_GET['ID'];
// use $ID for displaying invoice

Related

How to create PHP pages by following an order?

I am working on building a Webstie for a restaurant and because clients will need to be able to order the items from the menu I've got to store everything on a MySQL database.
Now, everything is going to be organized visually in "cards"(you'll see what i mean in the image below) and each card is made up by an image and the title. Since I'm using PHP to deal with the SQL Queries and connection, the only thing I need is that once a card has been clicked, a new page gets presented with the same style, the same js scripts that I have, in other words, everything the same to the main page but with the correct number and type of cards.
You might have noticed that there are cards that create new pages with other cards inside and there are other cards, usually the last ones at the tree(image 3) that only create the menu. I've built everything and it works but all the data was stored inside JSON files and I had to copy the div for each card and create HTML pages for every category manually.
Now, I have already put everything inside the MySQL Database, I am referring to each item's data. So, what I need to do is simply create other html pages with different cards inside or create a menu(depending on the type of card). So, I understood that I need to create a tree, I thought about doing it in PHP in this way:
$tree = array("Drinks" => array(
"Alcholic" => array("Beers", "Vodka", "Wines"),
"Non-Alcholic" => array("Juices", "Something Else...")
),
"Food" => array(
//...
)
);
But, I don't have any idea about how to go from here. I tried my best to explain my objective in a clear and precise way. If, for any reason you need more details I will edit the post without any problems. This is a serious job and I will be very greatful for any amount of help I can get. Thanks in advance and have a great day!
You could use url parameter and do it all on one page, fetching data from db and creating cards dynamically based on the fetched result. For example:
if (isset($_GET['type') {
//suppose I clicked drinks
//then fetch drink types from db and and loop over them to create cards
//for example
<a href='index.php/?type=alcoholic'><img src='alcoholic.jpg'></a>
} else {
//show home page categories (drinks, food) if no parameter in url
//for example
<a href='index.php/?type=drinks'><img src='drinks.jpg'></a>
}
Alternatively, you could create separate pages for each subcategory, but that would be just duplicating the code.

Generate ID card through fpdf, php and mysql

I want to generate ID card for the students admitted in the college.
i have linked a photo in which i am sharing as to how the i want the id cards in pdf file through php and fdpf. and i am fetching the date from mysql.
Suppose i have 13 students available for a particular course. Now, i want the data to first actually work multicolumn wise and then as the page is filled, it should create the back side of the page in next page and move on to other page. On one A4 page, i can have only six ID cards and on the next page, six backside of those id card and again this step should repeat. I am confused.
You can use the AddPage() method to simulate a page feed. To add two pages, call it twice.
There's a third-party script to use a different margin for odd and even pages, like in a book, but I don't know if you can force double-sided printing from a PDF document.
when you are trying to generate ID then what should your goal is to generate six on a page and you can do that with looping.
Because printing on backside is printer property.

Creating product relations using PHP/Ajax/jQuery

I'm working on a self-made e-shop CMS and in the backend and I need to be able to create relations between products. When adding a new product I want to be able to open a popup window in which I can select the related products and then, when I close the window, I need the selected items to be sent back to a field on my page (ie comma delimited string with the selected values). It doesnt HAVE to be a popup window, I'll be glad to use any other method as well, as long as it does the above.
Which ways can I do this? I know Ajax/jQuery will probably do the trick but I don't have much experience with them.
There are a lot of ways to achieve that. One of these in the following scenario:
First: You have a PHP script that connects to the database and get your data.
$query = "your query";
$results = mysql_query($query);
$yourdata = array();
while ($row = mysql_fetch_array($results,MYSQL_ASSOC))
{
/* format the data in JSON format*/
}
echo json_encode(array("yourdata" => $yourdata));
Second: Using jQuery or JavaScript to make an ajax call to the script and then read the returned data from the PHP script and output it in HTML elements.
Or you you can format the data in your PHP script and use JavaScript to parse it and display it.
I can't show you a complete example here for all that but if you search around you will find a lot of examples.
I also highly recommend, if you want to get started with all of this, Head First jQuery, a fantastic book that gets you started with jQuery.
There are great chapters such as chapters 8 and 9 where you will find how you can use jQuery and ajax to get the data and pass it back.
You will find the example code in this link. Download the sample code for chapter 8 and 9 and try it.
For the popup window part there are a lot of plugins and there are also jQuery UI try this: Modal form.
I hope that will be helpful.

Lazy load from database as user scrolls down page (similiar to Twitter and Facebook)

I have a coupon code site. On some category pages I'm limiting it to display only 50 coupons as there are potentially 1000's of coupons for each category. I don't display them all as it would be hard on the server, and the browser will hang. Is it possible to lazy load more coupons as the user keeps scrolling down?
The only lazy load plugins I've found are for images. Anything out there that will work with PHP and loading data from a MySQL db?
Any help is appreciated. Thanks!
You will definitely need javascript or jquery for this. Just use an onScroll event when the scroll-bar is for example at 75% call a php-file using AJAX, pass 2 parameters for the query. Using the SQL Limit you need to set the start-indicator and the number of rows you want to collect: SELECT * FROM tbl_coupons LIMIT 50,20
You can use let the php output the html you want to use and insert the html straight into the Dom or if you want to parse the data using JS you can use *json_encode* to create a json-object from an array of rows.
do you mean like this one http://www.webresourcesdepot.com/dnspinger/
Personally I would do it with ajax, as soon as the browser detects a scroll it start to load the next coupons from the db, once they are loaded it will display them. I'm not aware of a script that would do this automatically, but it's not difficult to code with jquery.
Another idea would be to cache the coupons page, assuming they don't change every second it could be a feasible solution.

Refresh Using Ajax/PHP

Further to my question yesterday (here), I am working on a webpage that has a section that shows 'live' order details.
The top half of my webpage has Spry Tabbed Panels. One of the panels contains an include call to a separate php page that I have created (getOpenOrders.php). This contains an SQL query to obtain all open orders and then puts the details into a table.
As a result, the table of open orders is shown in the Spry panel. What steps do I now need to take to have this refresh every 15 seconds?
Do you really want to call the database every 15 seconds for each user? isn't that an overload?
I'm not saying that your database will be overloaded, but, thats how you shouldn't do things!
Edited
you should show an image, or the link to that page in order to gt an appropriate answer, because it all depends in what are you doing in the table.
because I don't know, I will give you an answer on what probably is happening.
Because you said that you're new to the ajax world, let's make things simple, and not to complicate on the you should return a JSON object and use it to re populate your table. :)
So we will start with 2 buttons (Previous and Next) so the user can move the data that is showing (you probably don't want to give him/her 100 lines to see right?)
let's say that you have 2 pages, a showData.php and getTable.php, in the showData.php you will need to load jQuery (wonderful for this) and add a little code, but where the table is to be placed, just add a div tag with an id="myTable" because we will get the data from the getTable.php file.
getTable.php file has to output only the table html code with all the data in, without no html, body, etc... the idea is to add inside the div called myTable all the code generated by getTable.php
Let's imagine that getTable.php gets a page variable in the queryString, that will tell what page you should show (to use LIMIT in your MySQL or PostgreSQL database)
You can use jQuery plugin called datatables witch is one of my choices, check his example and how small code you need to write! just using jQuery and Datatables plugin.
The first description follows the jQuery.Load() to load the getTable.php and add as a child of the div and wold do this for the previous and next buttons, passing a querystring with the page that the user requested. It's to simple and you can see the website for that, if you prefer to use the DataTables plugin, then just follow their examples :)
if you, after all this need help, drop me a line.
<META HTTP-EQUIV=Refresh CONTENT="15; URL=<?php print $PHP_SELF ?>">
This should be in between the head tags.
-or-
header('Refresh: 15');
This should be before the head tag and directly after the html tag.
As said by balexandre, a different method should be used. One that does not require a database hit every 15 seconds for every single user that is connected to the site. But, there is your answer anyways.
Although, balexandre makes a very good point, if you do decide that you need a refresh, you could simply do something like this in your JavaScript:
window.onload = function( )
{
setTimeout( 'window.location.refresh( )', 1500 );
}
(I've not tested the above code, so syntax may need to be tweaked a little, but you get the idea)

Categories