Printing Out A Table - PHP and MySQL

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Printing Out A Table - PHP and MySQL

abhiram
I've been designing an online registration page for my univ. The adminstrative section is going to take care of the registration and they've asked me if I could incorporate a PRINT link on the page which displays the details of the students so that they can take a printout directly of just the table and not the extra links and decorations on the page without having to copy the whole thing into excel or something. Does anyone have any ideas of how to do this?

To make myself more clear, here's a screenshot of the admin page:

user posted image

I want a printout of just the table and not of the form or links present at the top.

And it should be as easy as clicking a link. Any ideas? Any links will also be appreciated.

Thanks.

Reply

vujsa
I assume that the form inputs the data into a database. Just write another script to pull the needed files from the database and insert into a printer friendly version of the page.

I think that you may want to add a database table for database queries. When you generate the "FULL" feature page, insert the database query used to get the files for the table into it's own table then the link can forward the queries ID number to the printer friendly script. That script runs the sam query but builds a simple version of the table with the results.

Kind of like a database session. This could be used as a security log of who is searching and viewing what. You'd have too find a way to clean out the database though. Otherwise it would get real big real fast.

It is hard to say exactly what you need to do because I don't have all of the needed information.

vujsa

Reply

abhiram
Hey ... that's a grand idea. I didn't even think of the need to log all the database queries. I guess it'll be required in the event of any abuse right? I'll look into it. But, maybe, instead of a database query log, isn't a database of people logging in sufficient? I mean, just note down who is logging in at what time?

A printer friendly page sounds great. I wonder why I didn't think about that. I think I can create a link to output the same details as the person is viewing to a new window which can then be printed.

Thanks a lot Vujsa smile.gif.

Btw, the form on the top is for filtering out the results. There is an edit button on the side which will enable the administrative section to edit the details of any student.

Reply

vujsa
What I was thinking was an on event database item delete.

Imagine this is you database query for mySQL:
CODE
$sql = "SELECT id, name, birthday FROM table_name ORDER BY id";


Then you can insert that information into the new table with a few extras:
CODE

// Insert a Database Query Into the Log
$query_string = $sql;
$query_time = time();
$query_id = md5($query_string.$query_time);
$table_name = "DB_queries";

$sql = "INSERT INTO $table_name (id, query, time) VALUES ('$query_id','$query_string','$query_time',)";
$result = mysql_query($sql, $connection);

// Clean Out Old Log Entries
$entry_expire = 300;  // Number of seconds to keep a log entry 5 minutes shown here.
$expire_time = $query_time - $entry_expire;

$sql = "DELETE FROM $table_name WHERE time <= $expire_time";
$result = mysql_query($sql, $connection);


Then just create a link wto you printer friendly script:
CODE

echo "<a href=\"printer_friendly.php?".$query_id."\">Printer Friendly</a>";


Then just kind of take it from there. You should be able to use the stored DB query to pull the same information from the database for a text only version of the page. You wouldn't need to have a cron job to clean out the database since the database is checked for old log entries every time the original table is generated. The down side to this is that you would add 4 database queries just to display a printer friendly page. It will add to the servers burden. You can cut one query out by storing the $result of the query instead of the actual query string. Since you would already have the array of information stored in the database, the need to perform the query over is not required.

This is only good if you plan to keep the "log" free of older data. If this isn't to be used as a security log as well and the log is cleaned out after 5 or 10 minutes it would be ok. The reason is becuase of how large the $result array could be if say 100 student files were selected. So it is a toss up between number of queries and the size of the database table.

That was just what I would do if I were you as I understood your question.
[hr=0][/hr]
Does the form above work with javascript and simply hide the table rows which don't match or is this serversided and the database is queried each time? I could probably come up with additional methods if I had a better understanding of what your existing script is doing.

Happy Coding. cool.gif

vujsa

 

 

 


Reply

abhiram
Sorry I didn't reply sooner. I was a bit busy with my projects and stuff.

That's a pretty neat idea. The form on the top queries the database each time. So, in effect, I think I just need to include a link on the top or bottom of the page which will pass the same query to another page without the form on the top. All that the form does is select who or what results you want to see. You can select entries according to the hostel, room no., preferred caterer and so on. And whenever you submit the form, the server queries the results and displays them according to the paging constraint, that is, number of rows to be shown in each page. Each time the page is refreshed or anything, the required rows are queried again.

I'll have to work on this over the weekend, it's due to be in proper working condition by monday. I'd post the code, but it's in too much of a mess because of the search form on the top. I'll use your code and see how it works out. I just need to maintain a log of all the people who are logging into the admin page and what changes are they making. In fact, maybe I don't even need to store the queries that are being viewed ... maybe only queries which result in a change of a student's profile will be needed.

Thanks a lot Vujsa smile.gif. Btw, how much of a load do 4 extra queries add to the server? Since the admin page will be used by at most a 2-3 people at a time, it shouldn't be too much. The students page will need to allow around 4000 students to register, so I think I better not log their activities.

Reply

vujsa
You know, if your form at the top is already doing all of that work, then you can just add one extra step.

You currently have 2 buttons "Show" and "Reset". I thin you could add a third button for "Printable"

It would be nearly the same as the "Show" buttuon but should trigger an additional function to only display the table. You can add a JavaScript event to the button to actually run the script in a new pop-up window.

To create your original page, you probably have a chunk of static HTML ith maybe a variable holding the dynamic HTML that shows as a table. If your table HTML was saved in the variable $table, then you could just used that variable in the printer friendly display and just use plain HTML before and after it.

Then you could break your output for either page into 3 sections: Header, Body, Footer.

The Body (table) could be built the same for both pages. It is just a table after all.
The Header and Footer would differ between the 2 pages. The printer friendly page would use a plain Header and Footer while the original page would use the current Header and Footer. The Header and Footer would be selected based on which button was pressed.

Then just add a couple of if statements to determine which button was used.

This wouldn't actually add to much to the existing script.

Hope This Helps,

vujsa

Reply

abhiram
I think a print button will be cool. But, instead of trying to divide the entire code into 3 sections, maybe it'll be easier to just write another 'print.php' and copy the stuff that makes the table into it and pass the variables that are required to print it. That way, I won't have to bother about readjusting the code in the main page and can have it print whatever I want in anyway I want. This will give me more flexibility in changing the final look of the print page.

This way I've got the print page working out ok. But have to start working on the logging script.

Here are links to the main script and the print page. The main page is just the part of the script which displays the form and the table. I've seperated the entire app into different parts as 'adminmain.php', 'adminprofile.php' and so on. 'admin.php' is the main file into which the other files are 'included'. Be warned that I've made a complete mess of the variables and I've used both global variables and non-global variables also. Right now, I'm not emphasising on 'clean' code.... if it works, that'll do. wink.gif
This is the first time I'm making an app this big all on my own.

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : printing, table, php, mysql

  1. Letting Users Add Mysql Data With Php
    (1)
  2. Mysql Question(inserting Number From A Textfield)
    (3)
    Hey! I am trying to do a "Admin give EXP script". But I can't make it work. The value is
    not updating, but the update query is correct.( I think:P) I think the fault is here: CODE
    $expcomp=$givexpp['exp'] += $givexp; The $givexp is the
    variable for the amount of Xp the admin wants to give. the $givexpp is the variable for the
    user info (in this case, the experince he already have). The datatype for the XP in the database is
    INT. So I have no idea if it can take data from a normal textfield. If you need to see all....
  3. Making Something In Mysql Happen Only Once
    (10)
    Hey! I know I am asking alot. But much is happening theese days. Sorry if I disturb with my
    questions. The thing I am trying to do is: Ex. If the user becomes level 2, he should get 5 skill
    points. I can't do this: CODE if($userlevel=5){ mysql_query("UPDATE
    user SET skillpoints =$points+5");} because then it would update everytime the code
    was loaded. I hope you understand what I am trying to do. If not, tell me /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> and i'll try to explain....
  4. Making A Link = Mysql_query
    (8)
    Hey! I will try to make this as clear as possible. how can I make the following. I have a
    list, of all members on my site. If I press on a members name(link), I will come to his profile. To
    come to his profile, I need to get out some vaule from the database, but to get out some value from
    the database, I must tell the code, how it should know who the user is (hard to understand?). To do
    that, I must add a mysql_query in the code ( I think), like "SELECT user FROM dbname WHERE
    user=link".. This is just how I think it works. I know it is kinda wrong.. but I don'....
  5. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...
    This Is for My attack Script. (4)
    Hey. I am making a "Version 2.0" For my attack script, but I can't make it work. This is the
    error I am gettin: Warning: mysql_result(): supplied argument is not a valid MySQL result resource
    in And here is the code: CODE $dbQueryHealth = mysql_query("SELECT
    temphealth FROM characters WHERE user =".
    $_POST['atkuser']."");           $currentHealth =
    mysql_result($dbQueryHealth, 0);         $dbQueryExp =
    mysql_query("SELECT exp FROM characters WHERE user = ".$....
  6. Warning: Mysql_num_rows()
    What is the error :S (1)
    Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I
    changed something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied
    argument is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31
    Here is the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM
    user WHERE username = '". $username ."'";                 if(
    mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )      ....
  7. Anyone Know Of A Really Good Mysql Class?
    Looking for something easy but full featured. (4)
    Generally speaking, when I write a script, it either utilizes the MySQL class of the parent system
    (like Mambo or Joomla) or I use basic functions and snippets to perform the database queries I need.
    I really like the Joomla database class as it allows you to simply pass a regular query string to
    it and the data is returned without the need for extra work! The Invision Power Board (IPB)
    database class which is what is used for this forum is kind of a pain to use since it wants the
    query string in a non-MySQL standard format. Nonetheless, it does work and I could u....
  8. Extracting Mysql Maths Using Php
    (2)
    Right, this is a really simple thing and it has me completely stumped. I'm working on this mini
    maths function and for some reason i cannot seem to do some simple math process using mysql. This is
    the code: (php btw), now assume that $date is actually a defined mysql date variable already
    successfully extracted. $sql = mysql_query("SELECT TO_DAYS('CURDATE()') -
    TO_DAYS('$date')"); while ($row = mysql_fetch_array($sql)){ $diff =
    $row ; } Can anyone spot what im doing wrong becuase im just thrown by it.....
  9. Too Many Connections?
    mysql_connect() (4)
    I uploaded my PHP game yesterday, and most of my friends tried it out. After a while, I tried to
    play as well but it said that mysql_connect() had too many connections already. Can anyone tell me
    how to increase the amount of connections or maybe the total amount of connections allowed?....
  10. Php/mysql And Manual Page Caching?
    (4)
    I am hopefully about to attempt this on the news page of my new site. Every bit counts as far as
    I'm concerned and not having "news" portion of my news page re-php and re-mysql everything where
    there is no chance seems like a waste. I'm looking for good articles, information or tips on
    the process (if I fail to find any good information as I'm looking through now). The way I see
    it right now, I have most of my page split up in header, content (some static html in here before
    dynamic contend and then a little more static html to close it off) and then a foo....
  11. Sql Injection Prevention (passing Numerical Data Across Pages).
    PHP/mySQL (9)
    Even if your building something as simple as a basic news page for your website, if your passing
    along url variable strings like (mysite/index.php?page=1), you may be vulnerable to SQL injection
    attacks. For cases like these (passing numerical data in url strings), I have a handy dandy little
    function to thwart these attempts silly: CODE // For checking if value is a number, if not
    return 1. function isNum($val) {   if (!is_numeric($val)) {
    $val = 1; }   return ($val); } I have this function, within my ....
  12. Php Mysql Errors
    Fetching arrays (2)
    I am deciding to make a Multiplayer Online RPG type game. I will be building it off of PHP and MySQL
    to ensure makimum compatibility with Astahost's services (and it makes it easier /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />). I have a database setup with
    1 table to hold user data and I have the login system setup properly as well as the registration
    form (obviously). All games of course have something similar to gold, units and points. Because
    this is a turn-based game, I have turns. Now for the problem: I am trying to echo ....
  13. How To Show Serial Nums In PHP Table For Contents Of MySQL DB
    Serial Numbering for output contents of mysql in php table (4)
    Hello there, I'm looking for some education. How would you show the serial numbering for
    outputted contents of mysql database. I used a table created in PHP to output content (i.e. an
    alumni database) and I created a column for S/N, so that at a glance anyone can tell how many
    members have registered. Thanks house. Neyoo....
  14. PHP & MySQL: Displaying Content From A Given ID
    (6)
    Okay so I got this sample link (not working): http://www.acosta.com/joo.asp?id=654 Now suppose
    I have a PHP file that would use MySql in order to get all values in the row where id 654 is found.
    Here's a sample DB: Table: demnyc ______________________________________ | id |
    Name | Age | Email | *----------------------------------------------------* | 1
    | Albert | 17 | no email |
    *----------------------------------------------------* | 2 | YaPow | 888 |
    no email | |__________....
  15. Re-order MySQL Table
    (11)
    Hello you all, I've got a question /smile.gif" style="vertical-align:middle" emoid=":)"
    border="0" alt="smile.gif" /> Let's say I have a database width the table "news". It contains
    about 10 items which is ordered by the field "id". Now from my admin page i do this: CODE
    <?PHP mysql_query("DELETE FROM news WHERE id=4"); ?> And a few days later
    i do: CODE <?PHP mysql_query("DELETE FROM news WHERE id=7"); ?> Now
    there are two gaps in the table => 1, 2, 3, 5, 6, 8, 9, 10 (no 4 and 7). It want to real....
  16. Need MySQL Alternative To The Syntax "or die()"
    (8)
    Hello again /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
    I'm facing a problem with PHP and MySQL... I want, when a MySQL error occurs, to let the script
    continue. Here's the script: CODE $query = "SELECT * FROM menus ORDER BY id
    ASC"; $menus_result = mysql_query($query) or
    die("Error!"); while(
    $menu=mysql_fetch_array($menus_result) ) {    echo
    $menu['name']."<br />"; } Now if the table "menus" doesn&....
  17. Need Help With Php/mysql And Web Servers Such As Asta's.
    (4)
    Within my site I have built my own basic forum using PHP/Mysql, I always test locally now both using
    EasyPHP and WAMP5 which both give me no problems what so ever. But when I tryed to run the exact
    same code on Asta's hosting services (and possible another I used to use) when creating a new
    thread or adding a reply to an existing one it *sometimes* adds an additional thread/reply as a
    Guest (someone not signed in) with an empty message. This would lead me to believe that somehow the
    page is being refreshed and the variables sent to the database update php file are ....
  18. Important: Basics Of Using PHP And MySQL
    (9)
    I generally notice confusion with new users to PHP and or MySQL and first of all I believe that
    unlike HTML which is automatically associated with a IE browser in a Microsoft system. HTML is
    automatically rendered with whatever browser is the default browser, be it Internet Expolrer Firefox
    Netscape or any other browser that has been set. PHP is a different matter to view the output of a
    PHP file it must be run on a webserver, and if you do not have one set up on your local PC it simply
    will not work. (Note serverside langauge requies a server) HTML is client side and ....
  19. How Do You Create A Secure Loging?
    with PHP and mySQL (4)
    I've read a few articles, and looked up the code of certain files and some of them seem to work
    differently. I'm trying to create a login script, which would require PHP and mySQL to run,
    however, I'm not quite sure how to approach it since I'm only just learning PHP. I'd
    like to know, what is the most secure and effective login? I've heard you can add a salt to
    encrypted passwords, etc, and well as using sessions (sid). It's just like to know what methods
    are best for creating a secure login script. Thank yo ufor readin this. ....
  20. [php] Index.php?section=xx&pag=yy
    No MySQL or any other database (6)
    Hi everybody. This is my 3rd script, but this dont use MySQL It does this: divide the site in
    SECTIONS and PAGES. Benefits: -You have to create just the text of your pages, no create ech page
    with the entire layout again. -If its just the text that is included, you just have to have one page
    with the layout, witch is the INDEX.PHP. -If you chanche the layout in the index.php, you DONT HAVE
    TO change in the other pages. Here is the code: CODE <?php
    //-----------------------------------------// //ACAF Paginação                           //
    //by Alexandre Cis....
  21. [PHP + MySQL] Encrypting Data
    To protect the password of your DB, for example. (9)
    Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the
    MySQL DB. Here we go! ------------------------------------------------------------------------
    CODE <?php $password = "abc"; $new_password = md5($password);
    echo $new_password; ?> The password "abc" was codfied using md5() This will be:
    900150983cd24fb0d6963f7d28e17f72 CODE <?php $normal_pass = "abc";
    $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($norm....
  22. [PHP + MySQL] Separating The Results By Pages
    Simple code (0)
    Hi! I will post here a code for separating the results of MySQL in pages. You ask: Why separete?
    I answer: Imagin that you have 1523 results to display. I dont have to say anything. =P Here is it.
    ------------------------------------------------------------------- CODE <?php $conect
    = mysql_connect("host","user","password"); $select_db =
    mysql_select_db("database"); $query = "SELECT * FROM mytable";
    $results = "15"; //Number of results displayed per page. if (!$p....
  23. Need Some Help Using PHP & MySQL
    (4)
    I wonder if its possible or if anyone know how to : I'm making a website for my soccer team
    and every week there are new news, but in the index file i only show some part of the text and the
    rest of the news is in Stored in Database, of course that all news are inside mysql database, i only
    set a script to get from the Database the text and title and so. My doubt is if there is some how to
    attach a link to that news and when i run the link, this show me another page but with FULL news
    text ? i Read something like, i've to create a cicle CODE <....
  24. Need For PHP/MySQL Creator
    (1)
    need for PHP/MYSQL creator I need a PHP/MYSQL application creator that have php function and
    create php codes automatically, for example:Macromedia Dreamweaver MX 2004 have this ability to
    create php applications already i downloaded PHP designer but it didn`t applications ....
  25. Need Help With A PHP - MySQL Registration Script
    Wont INSERT into the database (13)
    hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE
    <?php # register1.php # common include file to MySQL include("DB.PHP");
    $Username=$_POST['Username'];
    $Password=$_POST['Password'];
    $Name=$_POST['Name']; $Last=$_POST['Last'];
    $Sex=$_POST['Sex']; $Month=$_POST['Month'];
    $Day=$_POST['Day']; $Year=$_POST['Year&....
  26. Php/mysql Data Display
    (3)
    Okay .. got a bit of a question here, so I'll do some explaining. I was asked to do a site for
    an online roleplaying game, specifically, a "blackbook" site. I accepted and began my quest for
    knowledge of PHP. I've gotten quite "far" to the point that I can now take a user inputted
    search value and query the database with that value, and then display the values in a table. My
    MySQL table setup is as below: CODE |Name|Reports|Type1|Type2|Quote|Confirmed| When queried
    it displays the following: CODE Violator Name: ['Name'] # Repor....
  27. Php/mysql Function Problem
    (2)
    I am having a problem with some of the php/mysql functions. What I want to do is display the
    results that a MySQL shell would give a user when executing a query. Using the mysql_query()
    function I get a resource, but the mysql_fetch_row() and mysql_fetch_object() functions do not seem
    to be working. If requested, code can be provided, but what I'm looking for is more of an
    example on how to use these functions or other functions to display the output of a query. Thank
    you. ~Viz....
  28. Help With Multi Tier Mysql Application Over Net
    receiving data connection from client (6)
    hi.. i want to make a connection from my desktop client into mysql database at web server.
    currently i think it can be provided by PHP. 1. i'm thinking like this: CLIENT -> PHP + MYSQL
    CLIENT {sent file} -> PHP {receive file, open connection to MYSQL, insert data from file} how it
    will be done ??? 2. the security do you know how to secure it ? thanks......
  29. Displaying Data From Mysql?
    (2)
    how can i display data from mysql with php, just that on one page i want to display only the first
    10 things and the next page the next 20 ...etc.. how can i do that? ....
  30. MySQL & PHP coding
    (9)
    So it seems as though the php docs make it very clear that mysql and mysqli functions will all
    connect to the database as a latin1 client. Although i have my server set up with utf8 databases,
    tables and fields and the default client connection is utf8, php still connects as latin1. My
    xhtml forms and pages are all utf-8, so when i post utf8 data and insert it into the database the
    connection assumes that incoming data is latin1 and the data that gets placed in the database is
    invalid. phpMyAdmin seems to be able to view, add, edit, and retrieve utf8 strings in the d....

    1. Looking for printing, table, php, mysql

Searching Video's for printing, table, php, mysql
Similar
Letting
Users Add
Mysql Data
With Php
Mysql
Question(ins
erting
Number From
A Textfield)
Making
Something In
Mysql Happen
Only Once
Making A
Link =
Mysql_query
Warning:
Mysql_result
(): Supplied
Argument Is
Not A Valid
Mysql Result
Resource In
... - This
Is for My
attack
Script.
Warning:
Mysql_num_ro
ws() - What
is the error
:S
Anyone Know
Of A Really
Good Mysql
Class? -
Looking for
something
easy but
full
featured.
Extracting
Mysql Maths
Using Php
Too Many
Connections?
-
mysql_connec
t()
Php/mysql
And Manual
Page
Caching?
Sql
Injection
Prevention
(passing
Numerical
Data Across
Pages). -
PHP/mySQL
Php Mysql
Errors -
Fetching
arrays
How To Show
Serial Nums
In PHP Table
For Contents
Of MySQL DB
- Serial
Numbering
for output
contents of
mysql in php
table
PHP &
MySQL:
Displaying
Content From
A Given ID
Re-order
MySQL Table
Need MySQL
Alternative
To The
Syntax
"or
die()"
Need Help
With
Php/mysql
And Web
Servers Such
As
Asta's.
Important:
Basics Of
Using PHP
And MySQL
How Do You
Create A
Secure
Loging? -
with PHP and
mySQL
[php]
Index.php?se
ction=xx&
;pag=yy - No
MySQL or any
other
database
[PHP +
MySQL]
Encrypting
Data - To
protect the
password of
your DB, for
example.
[PHP +
MySQL]
Separating
The Results
By Pages -
Simple code
Need Some
Help Using
PHP &
MySQL
Need For
PHP/MySQL
Creator
Need Help
With A PHP -
MySQL
Registration
Script -
Wont INSERT
into the
database
Php/mysql
Data Display
Php/mysql
Function
Problem
Help With
Multi Tier
Mysql
Application
Over Net -
receiving
data
connection
from client
Displaying
Data From
Mysql?
MySQL &
PHP coding
advertisement




Printing Out A Table - PHP and MySQL



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE