Jump to content

Recommended Posts

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!

 

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.

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.

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?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.