runnerpaul Posted February 12, 2011 Share Posted February 12, 2011 Hi, I have the below code which pulls pet types from the database, and when you pick the particular type by selecting a radio button amd press 'Select Pet Type' you are brought to a page listing all examples of that pet. Is there any way of changing this so the pet types are listed as hyperlinks instead and when you click each particular hyperlink you are brought to a page where that pet type is listed? <?php /* Program: PetCatalog.php * Desc: Displays a list of pet categories from the PetType table. Includes descriptions. * Displays radio buttons for user to check. */ ?> <html> <head><title>Pet Types</title></head> <body> <?php include("misc.inc"); #12 $cxn = mysqli_connect($host,$user,$password,$dbname) #14 or die ("couldn't connect to server"); /* Select all categories from PetType table */ $query = "SELECT * FROM pettype ORDER BY petType"; #18 $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); #20 /* Display text before form */ echo "<div style='margin-left: .1in'>\n <h1 style='text-align: center'>Pet Catalog</h1>\n <h2 style='text-align: center'>The following animal friends are waiting for you.</h2>\n <p style='text-align: center'>Find just what you want and hurry in to the store to pick up your new friend.</p> <h3>Which pet are you interested in?</h3>\n"; /* Create form containing selection list */ echo "<form action='ShowPets.php' method='POST'>\n"; #33 echo "<table cellpadding='5' border='1'>"; $counter=1; #35 while($row = mysqli_fetch_assoc($result)) #36 { extract($row); #38 echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n"; echo "<input type='radio' name='interest' value='$petType'\n"; #43 if( $counter == 1 ) #44 { echo "checked"; } echo ">$petType</td>"; #48 echo "<td>$typeDescription</td></tr>"; #49 $counter++; #50 } echo "</table>"; echo "<p><input type='submit' value='Select Pet Type'> </form></p>\n"; #54 ?> </div> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/ Share on other sites More sharing options...
Jessica Posted February 12, 2011 Share Posted February 12, 2011 Is there any way of changing this so the pet types are listed as hyperlinks instead and when you click each particular hyperlink you are brought to a page where that pet type is listed? Did you try? Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173195 Share on other sites More sharing options...
runnerpaul Posted February 12, 2011 Author Share Posted February 12, 2011 Lol yeh. Came up with the following based on stuff I came across on a Google search. Creates a text box though. I'm guessing its something fairly straight forward but just havnt worked it out yet. I have actually messed about so much that I have got a bit frustrated so am going to take a few hours break. I thought I might put up a post in case somebody has experience of this and could offer a few pointers. echo "<li><form action='ChoosePetName.php' method='POST'> <input type='hyperlink' value='hyperlink' name=$petType value=$petType\n"; echo "/> </form>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173204 Share on other sites More sharing options...
Jessica Posted February 12, 2011 Share Posted February 12, 2011 If you don't yet know the difference between an input and a link, I'd suggest some HTML tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173206 Share on other sites More sharing options...
runnerpaul Posted February 12, 2011 Author Share Posted February 12, 2011 Im aware of the differences between input and a link. Basically I came across several things that looked like they might work but had very little explanation around them and when I tried them they didnt work. eg: <a href='ChoosePetName.php?petType'>$petType</a> That mightnt be exactly what I came across but its along the lines of what I saw. However when it didnt work I searched a little further and came across what I had in the last post. I know its not a link but as I couldnt get a link further and when I came across this while searching for ways to create links in php I thought it may be worth looking into. Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173228 Share on other sites More sharing options...
litebearer Posted February 12, 2011 Share Posted February 12, 2011 Do NOT use them (the hyperlinks) as a form element. IF there are a long series of choices, list them in a scrolling div or drop-down menu Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173231 Share on other sites More sharing options...
runnerpaul Posted February 12, 2011 Author Share Posted February 12, 2011 Ah yes. I could create a drop down menu. I was just wondering if it was possible basically get the same results using hyperlinks. Can this be done not using forms? The only reason I ask is that I think it would look better in the site I am creating. Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173235 Share on other sites More sharing options...
litebearer Posted February 12, 2011 Share Posted February 12, 2011 visually, a scrolling div is extremely similar to a select field in a form. As far as I know, 'hyperlink' is NOT a valid form field type. Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173242 Share on other sites More sharing options...
chaseman Posted February 12, 2011 Share Posted February 12, 2011 Your wording is a little vague, are you asking how to execute PHP through a hyperlink? Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1173392 Share on other sites More sharing options...
runnerpaul Posted February 14, 2011 Author Share Posted February 14, 2011 Essentially yes. My current script pulls information on pet types from the databases and assigns a radio button to each. If a particularly radio button is selected and the 'Select Pet Type' button clicked, all instances of that pet type are displayed on the next page. I wish to change these radio buttons for hyperlinks. Therefore I would like a hyperlink for each pet type. If one is clicked the next page will show all pets of that type. Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1174077 Share on other sites More sharing options...
runnerpaul Posted February 16, 2011 Author Share Posted February 16, 2011 Think I'm getting somewhere with: for ($i = 0; $i < mysqli_num_rows($result); ++$i) { $line = mysqli_fetch_row($result); echo "<a href='ShowPetsMembers.php?petType=".$line[0]."' name='category'>".$line[0]."</a>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/227452-using-hyperlinks-instead-of-radio-buttons/#findComment-1175197 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.