url variable link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
berniez
Forum Newbie
Posts: 1
Joined: Mon May 11, 2009 9:14 am

url variable link

Post by berniez »

Hi I have a page1 with a variable link page2.php?cat=Accomodation&list=Backpackers Hostel then on page2.php I have

Code: Select all

<?php 
$cat = $_GET['cat']; 
$list = $_GET['list'];
echo ("{$cat} : {$list}");?>
which works perfectly and displays Accomodation : Backpackers Hostel
How do I get the echo part to turn into links. I need on page2 the 'Accomodation : Backpackers Hostel' to be made into links that I can click on them. 2 separate links, 1 for Accomodation and the 2nd one for Backpackers Hostel.
Could someone please help I am at a total loss as to convert them to links.
Thanks for your help
Last edited by Benjamin on Mon May 11, 2009 10:15 am, edited 1 time in total.
Reason: Added [code=php] tags.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: url variable link

Post by Yossarian »

Code: Select all

<?php
 
if( isset( $_GET['cat'] ) ){
 
// make it safe to display on a html page, escape it
  $cat_output = htmlentities( $_GET['cat'] ) ;
  echo '<a href="anotherpage.php?cat=' . $cat_output  . '">' . $cat_output .  '</a> ' ;
}else{
// category not set
 
}
 
?>
Look carefully at the html source code of the page to make sure that the use of quotes does not get mixed up, there are lots of ways of using quotes.
Post Reply