Joefunkx Posted June 18, 2007 Share Posted June 18, 2007 Hey guys, I have searched for help on this but haven't found anything. I'm relatively new to PHP so this may be a stupid question. Basically, I have a .php page which uses data from a form to search through a database and echo out the results. Here is my problem. For each result, i want to be able to link to that result's page by somehow pulling the "id" off of each database entry. Here is an example- a search for vehicles is made and the following results are found in the database and displayed on the screen- Honda Volkswagon Subaru Now, i want to be able to click on each of those results and have it directed to that result's page (either one page the gets repopulated with data depending on which one is clicked, or seperate pages for each) I tried the following - <A HREF="<?$name?>.html"> and my theory there was that I would create a page for each, so "Honda.html", "Volkswagon.html" and "Subaru.html". I hoped that it would take the $name field from each entry and populate that into the URL for the link, but obviously that didn't work. Maybe it would be easier to make one page to link to and have that single page pull data depending on which result it was accessed with, though i don't know how to do that either. Anyway, I would appreciate any help you guys can give me. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56068-help-with-php-search-results-leading-to-different-pages/ Share on other sites More sharing options...
akitchin Posted June 18, 2007 Share Posted June 18, 2007 this is the beauty of PHP - anything can be dynamic, even pages. you can send the user to a page with a variable set, and display the appropriate content: <A HREF="car_lists.php?make=<?$name?>"> and on car_lists.php, you can access $_GET['make'] for the assigned make from that link. be warned however - treat user input as potentially malicious, ALWAYS. filter your $_GET['make'] for the appropriate possibilities, and toss off any that are invalid. this is a VERY important part of designing a page that uses user input (as anyone could link to, for example, car_lists.php?make=SOMETHING_BAD_THAT_DESTROYS_YOUR_ENTIRE_COMPUTER_FOREVER!!!). take that with a grain of salt - they can't literally destroy your computer, but you get the picture. Quote Link to comment https://forums.phpfreaks.com/topic/56068-help-with-php-search-results-leading-to-different-pages/#findComment-276910 Share on other sites More sharing options...
Joefunkx Posted June 18, 2007 Author Share Posted June 18, 2007 Thanks for the help! Now, I'm still kind of stupid when it comes to this stuff so how would the $_GET script work? Or I guess in better terms, what code do I need to include in that second .php file? Quote Link to comment https://forums.phpfreaks.com/topic/56068-help-with-php-search-results-leading-to-different-pages/#findComment-276938 Share on other sites More sharing options...
akitchin Posted June 18, 2007 Share Posted June 18, 2007 use $_GET['make'] to extract and display the appropriate data, the execution of which would depend on how you're storing your information. assuming it's from a MySQL db, you'll need to use the typical set of MySQL functions to do the work. Quote Link to comment https://forums.phpfreaks.com/topic/56068-help-with-php-search-results-leading-to-different-pages/#findComment-276939 Share on other sites More sharing options...
Joefunkx Posted June 18, 2007 Author Share Posted June 18, 2007 to test it I did the following - put following link in first php file <A HREF="displaylisting.php?mls=<?$name2?>"> put following code in displaylisting.php file to test <?php echo $_GET['mls']; echo $name2; ?> that doesn't give me anything, however if i hardcode a value into the link it displays that value on displaylisting.php page, like the following- <A HREF="displaylisting.php?mls=123456"> What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/56068-help-with-php-search-results-leading-to-different-pages/#findComment-277003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.