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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hyperlink data to php page 4

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
Sorry, but I am new to this. I've found all sorts of info on forms and check boxes, but nothing that answers my question.

I have a list of Hyperlinks displayed from my database:

while ($row = mysql_fetch_array ($result)) {
if ($row['COUNT(*)']>=2 {
print"<a href=\"page.php\">$row[CATEGORY]<br></a>";
}}

each [CATEGORY] has multiple listings in the database.

I want to use the link the user clicks to reload the current page "page.php" with the link data so I can use it to display those values in [CATEGORY].
 
So you want to submit data via a URL?

Use the $_GET variable, and a querystring.

i.e.

page.php?variable1=value1&variable2=value2

and so on
 
thanks for the reply, but I don't really want it to show in the URL. I want to set the CLICK equal to a $variable, reload the current page on the CLICK, and use the $variable to reaccess the DB to display more defined information based on the $variable.

That may be the question you answered, if so, I appologize, but I'm a lot newer to PHP(programming in general) than the answer.

Thanks again.
 
ok well if you dont want to show the url in the browser what about giving the link from the database an ID
so page.php?variable1=pageid

print"<a href=\"page.php?id=$id\">$row[CATEGORY]<br></a>";

or something similar
 
Thanks again skiflyer and Extreme43. Both answers helped me a lot. Like I said, I'm new and it takes me a while to understand the answers, but your advice was great. My new problem is with ...?id=$id\"... it cuts off part of the id I'm trying to carry over.

Ex. id= Arts & Entertainment only gets assigned 'Arts'. How do I get the whole string to be assigned the value?
 
Use urlencode()
Code:
echo '<a href="page.php?id=' . urlencode($id) . '">' . $row['catagory'] . "<br></a>\n";
This will render something line "one & two" as "one+&amp;+two" or "one%20&amp;%20two".

Ken
 
Ps.
You can also use an image as an submit button!
eg. you can have a <form> with submit, and action = "post".

Then you dont have to worry about querystring..

Code:
<INPUT type=image name="search" src="images/search.gif" border="0" />

Olav Alexander Mjelde
Admin & Webmaster
 
Thanks again, Wow I'm new to programming. Great info, I'm terrible with the syntax, but I made it work with your help.
 
thought I would share the final code, probably not efficient, but maybe someday...

$htlink=urlencode($row['CATEGORY']);
print "<a href=\"page.php?id=$htlink\">$row[CATEGORY]<br></a>";

Then on the page side:

if (isset($_GET['id'])) {$click=$_GET['id'];
echo $click //actually used this code to search db for CATEGORY, but you get the picture.

Thanks again for everyone's help. I know, too many variables and too much code, but I'm too new to know better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top