Re: Returning Results

From: Date: Wed, 20 Aug 2003 11:47:30 +0000
Subject: Re: Returning Results
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-29984@lists.php.net to get a copy of this message
In article <1EA7D3AE70ACD511BE6D006097A78C1E033C9216@USROCEXC>, Richard.Hutchins@Getingeusa.com says... > OK, I'll apologize in advance if this is a little off topic, but I think > it'll be close enough. > > I have a form (searchform.php) that collects data for a search (e.g., > firstname, lastname). That form submits to a separate PHP script > (search.php) that queries a database to find matching rows and returns the > information in an array ($results). > > All pretty standard stuff and it all works. > > I know I "while()" the information in the resulting array ($results) to draw > a table showing all of the results. But what that would require is the form > (searchform.php) to collect the data and submit to the search.php script > where HTML and PHP code combine in one file to perform the query and draw > the results. I know how to do this and have done it in the past. > > However, this instance has a wrinkle to it. When the searchform.php form > submits to search.php, I want to perform the query, but return the user (and > the $results array) to searchform.php to display the results. > > I want to stress that I can get the information from the database with no > problem. I'm just stuck on how to get the results back to the page that > called the search.php script in the first place. > > Is turning search.php into a function and "return"-ing the results the only > way to accomplish this? Because the only other idea I can come up with is > using a > header("Location:http://searchform.php?rs=$results"); > statement and > that doesn't seem to work (and logically, I can see why). > > I'm not asking for a total solution here because I can handle the whole > solution myself. However I would appreciate a bump in the right direction in > regards to how to architect the application logic. What about using the same script to provide the search form and process the results? If you use say a submit button to send the form, you can check the value of the button name and branch your script accordingly, like: switch $action: { case 'Search': // Button Search is clicked // do search and display results break; default: // No value for $action, e.g. first call of page // display the search form break; } Add other case values and season to taste :-) Cheers -- Quod subigo farinam $email =~ s/oz$/au/o; A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet?

« previous php.db (#29984) next »