Jump to content

Recommended Posts

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>

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";

 

 

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.

 

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.

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.

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";
}

 

 

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.