Print to paper selected data - php

I've a database (image1) and using PHPMaker i created the graphic interface (image2). What i want is to add a button at the bottom of the page that will print the selected data from the selected fields (image3).
Can anyone tell me how to do that?
Do i have to use php code or a javascript?

Just add a print link by echoing the following to create a "Print" link on the page
echo "<a href='#' onclick='javascript:window.print();'>Print Page</a>";
Button click will make the browser present the user with the default print dialog.

Related

HTML/PHP - Send data with link without using JavaScript

I'm new to web programming and I have a problem with the website I'm trying to do : I want to send some data to another .php page when the user clicks a link (there are several links, each link is the title of an newspaper article and when the user clicks one of them, it sends the id of the article because the next page has to load the content of the article). But I must not use Javascript.
Here is my previous code :
<h2> Articles </h2>
<?php
$articlesSql = "SELECT id, title FROM Article A, ApproveArticle VA WHERE A.id = VA.article AND VA.state='published';";
$articlesQuery = pg_query($connect, $articlesSql);
while($articlesResult = pg_fetch_array($articlesQuery)) {
echo "<form id=\"linkArticle\" action=\"article.php\">";
echo "<input type=\"hidden\" name=\"article\" value=\"$articlesResult[id]\"> </form>";
echo "<a href='#' onclick='document.getElementById(\"linkArticle\").submit()'> $articlesResult[title] </a> <br/>";
}
?>
Is there a way to avoid using Javascript? If so, how do I do?
Thank you for your help in this matter and have a nice day.
There is no way to submit a form without using a submit button with HTML only.
You can however make your button look like a link. This will require some CSS. Have a look at this thread for inspiration.
A better alternative that also solves your problem would be to ditch the form completely.
Simply include the article id you want to transfer to your PHP script into the URL as a parameter:
echo " $articlesResult[title] <br/>";
After the user clicked the link, you will be able to read the article id using $_GET['article'].

Custom print preview page with php and javascript

I would like to know if there is a way to customize the print preview page. I have a button on my page "Print page" and if I press it, I will get the print preview page. In this page there are some informations of users. I want to verify if the user that clicks this button is logged in and if so, in the print preview page will be only his informations. Thanks
You can set a specific print CSS style sheet. This could hide or show some things which should be hidden or only shown on the print output. This "print" style sheet does not affect the normal browser view.
Example HTML:
<div id="navigation">HOME</div>
<div id="print_copy_right" style="display:none">(c) domain.com</div>
Example CSS:
#media print {
#navigation_bar {display:none}
#print_copy_right {display:block}
}

php print a page bring up printer list

How do you bring up the printer list when you print a page in php? I've got the following code but is not bringing up the list of printers found on the pc.
echo "<a href='http://xxx/printme.php?$key' target='_blank' media='print'>Print Now</a>";
You can't do that with PHP. You need JavaScript for this:
<a href="javascript:window.print()">
You should use Javascript window.print() in an onclick event on your <a>
You can only print the current page.

Retain the page update by Javascript and run the PHP code?

In a php project I need to add items to database, list them & allow the user to edit & update items using a single page.
This is my code to edit item link in HTML table
echo ' Edit ';
When a user click on the above link I need to hide Add button and display two new buttons to Update & Cancel the edit + display selected item name in a Text box to Edit.
To hide and display buttons I'm using jQuery and to display the item name i need to use PHP.
Here when i put PHP code and reload the page with $_SERVER['PHP_SELF'] (as in above code), hiding & displying of buttons is lost after the page load. (If I remove the _SERVER['PHP_SELF'] code from link it hides and display buttons as expected (but no php code run))
How can I retain the page update by Javascript and run the PHP code?
I'm new to PHP am I missing something in my code?
$_SERVER['PHP_SELF'] is only a refrence to the php document itself, it doesnt contain any key/value pairs. try using:
echo '<a href=" '.$_SERVER['PHP_SELF'].'?'. $_SERVER['QUERY_STRING'].
'&name=edit&id=' .$rowCountry->CountryId .
' " id="edit" onClick="MyFunction()"> Edit </a>';
edit:
i may have misunderstood the question. you may need something like this:
<?php
if(!empty($_GET[edit])){
//echo code that u want to show AFTER they click the edit link
}else{
//echo the code to show if they have NOT clicked the edit link
}
?>

how to print a php page with table data

I have a search results in a form which displays a particular persons details.
Here what I need is I should have a print page button and print that search result.
How is that posible in PHP?
You can use the file -> print from the browser and use a CSS print
If you want a button to print on the website, you will have to use Javascript
<form><input type="button" value=" Print this page "
onclick="window.print();return false;" /></form>

Categories