Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Print contents in new window

Posted on 2006-05-10
5
Medium Priority
?
236 Views
Last Modified: 2008-01-09
I'm trying to redesign a web-based DB search that I've got running on my server.  As of now, the user enters some basic search criteria into an html form, these criteria are posted to a PHP script, and the script queries the DB and gets matching results.  Each resulting record from the DB is dumped into an HTML table, and the results page is a series of tables, each populated with a record from the DB.

What I want to do is change the initial results page to be a list of links, each one corresponding to a match from the DB.  If the user chooses the last name "Smith" to search, the results page would look something like:

Smith, Adam 10/12/1977
Smith, John  2/8/1980
Smith, Jonas 5/17/1966

I can get as far as outputting a list of links corresponding to the matches from the DB, but I don't know what to actually put *in* the links that will allow me to open a new window, dump code into it, and give the user an option to print.  Is this something I can do with pure PHP, or will I need to throw some javascript in there too?

What I was thinking was to create a class which is instantiated by each new result record from the DB.  The constructor would return the html of the link, which could just be echoed to the intial search results page as unordered list elements from within the while loop that gets the DB results.  When the link is clicked, the ideal action would be for another function in the class to be called, which would open a new window, dump the html-table-encoded results into it, and provide a "print me" link.  

Does anyone have any suggestions on how I might pull this off?
0
Comment
Question by:Zeek0
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
LinuxNubb earned 1200 total points
ID: 16652853
<a href='page.php?key=123' TARGET='_new'>Smith, John</a>

using target= will open in a new window

page.php will then using the key information to query the database for items to be displayed in the pop up.

0
 
LVL 6

Assisted Solution

by:ixti
ixti earned 800 total points
ID: 16664964
<?php
while ($row = mysql_fetch_array($result)) {
    echo "{$row['surname']}, {$row['name']} {$row['birthdate']}\n";
    echo "[ <a href=\"#\" onClick=\"javascript:PersonInfoWindow=window.open('extended_info.php?id={$row['id']}', 'PersonInfoWindow', 'scrollbars=1, width=700, height=450'); PersonInfoWindow.focus();\">info</a> ]";
}
?>

or link can be:
<a href=\"javascript:PersonInfoWindow=window.open('extended_info.php?id={$row['id']}', 'PersonInfoWindow', 'scrollbars=1, width=700, height=450'); PersonInfoWindow.focus();\">info</a>
0
 

Author Comment

by:Zeek0
ID: 16668539
So what I'm seeing is that I'll need two scripts, correct?  

The first will do an initial query for, say, the first name, last name, and birthdate.  The results will be displayed on a table of links, each to a second script with a GET variable.  The second script will query the DB again for the entire record(s) and build the print table out of them.

Is it better, performance-wise and efficiency-wise to use two queries, each one returning as little data as is necessary?  Or is that simply the way it has to be done?  In my case, performance is not a major issue because the database records are short and the maximum number of matches to a particular query would only be a couple dozen.  

It makes more sense to query only for the needed data, but to this point I was getting everything at once because I though the interaction between the script and the DB was the performance bottleneck.  Is that incorrect?  That is, does it hurt performance more to a) have the script receiving and parsing unnecessary data from the DB, in the interest of using a single query or b) query the database repeatedly with more restrictive statements that return less data?


0
 
LVL 9

Assisted Solution

by:LinuxNubb
LinuxNubb earned 1200 total points
ID: 16669499
If the php is running from the same box as the sql database, it's not going to matter that much.  The performance is very negligable.  If you grab more data than you need, you will take up more memory resources.  If you use more queries, you are relying on the speed of your TCP stack and the performance of the sql server.  Either way, it's extremely fast.

I personally would make 2 smaller queries that were more relevant.

With my example, you would have a query on each of 2 pages.  The first page builds the links.  And the popup window retrieves the data base on the clicked link.
0
 

Author Comment

by:Zeek0
ID: 16712034
Thanks for the info.  I got everything working and as far as I can tell, the performance is more than adequate.  Thanks for the help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question