Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value of hyperlink as lookup data 1

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

If this is the wrong forum for the question, apologies in advance for this newbie type question.

Would like to use the value in a hyperlink to be the value to search for in a database - alternatives welcome.

FI, to build a page of FAQs the <A></A> link text might be

[tab]How do I...?
[tab]Where can ...?
[tab]What is ...?
[tab]etc

but rather than go to another .htm page the value would be submitted like a form to a .php page whereupon the .php page uses the value to retrieve the answer to the question from a database and displays it.

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Append the parameter to the link URL like so

Code:
<a href="search.php?q=[i]search query[/i]">Search thing</a>

Then, in your PHP script (search.php) get the parameter from the querystring

Code:
$searchQuery = $_GET['q']


You can then do with it what you will.

Also note, that you should ensure it isn't possible to pass harmful data to your script via that parameter. So do some checks on it before anything else.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Hi

Right, not to much meaning in those words of mine. In fact I thought to what Foamcow already wrote :
Code:
<a href="search.php?q=[i]search+query[/i]">Search thing</a>
Where the "search+query" part is added dynamically. By the server-side script which generates the page.

Feherke.
 
Yes, that's what I meant.
Write the search query value out dynamically as you build the page & links.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Foamcow

Yet to implement this but following your suggestion the link would be contructed as
Code:
<a href="search.php?q=033">How do I update my application?</a>
where the string '033' is used to locate the corresponding record in the faq_data table and display the content of the memo or BLOB field in the .php page.

Please advise if the interpretation is incorrect.

TIA

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Yes.

So your search.php script grabs the value of 'q' and uses it to retrieve the data.

Just make sure you do a sanity check on 'q' to make sure it's the type of input your script is expecting before you do anything with it.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top