Print contents in new window

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?
Who is Participating?
<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.

while ($row = mysql_fetch_array($result)) {
    echo "{$row['surname']}, {$row['name']} {$row['birthdate']}\n";
    echo "[ <a href=\"#\" onClick=\"'extended_info.php?id={$row['id']}', 'PersonInfoWindow', 'scrollbars=1, width=700, height=450'); PersonInfoWindow.focus();\">info</a> ]";

or link can be:
<a href=\"'extended_info.php?id={$row['id']}', 'PersonInfoWindow', 'scrollbars=1, width=700, height=450'); PersonInfoWindow.focus();\">info</a>
Zeek0Author Commented:
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?

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.
Zeek0Author Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.