Forum Moderators: coopster

Message Too Old, No Replies

How to create dynamic page from link

         

meganp

5:53 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



Hi,

I'm practicing to understand and learn and have the following example. My page displays the state with the pet names under them, like this:

CA
Fido, Bowser,

FL
Kittycat, Red, Bones,

etc.

When the names are clicked, it presents a page like [domain...]

What I don't understand is how to make it so that when the name is clicked, it actually opens up to a formatted page, such as

Fido

Pet of Susie

Born May 5, 1999

(the values are in a mysql database)

At this point I get a page not found. I've looked for tutorials that might give me a clue how to achieve that, but haven't had any luck so am appealing to someone here who might be able to help me understand that concept.

Up to now I have been able to create a simple content management system on my other test pages, yet I just don't understand how to make a "real" page that shows the pet's name is clicked.
Here's the code so far for the memorials listings page:

 

<?php
$petID=$_POST['petID'];
// Connect to the database
require_once ('../Connections/mysql_connect.php');
// Get data
$states = "SELECT state FROM users GROUP BY state";
$result = mysql_query($states);
while ($row = mysql_fetch_assoc($result)) {
echo "<p>" . $row["state"] . "<br>\n";
$statename = $row["state"];
$allpets = "SELECT memID, petName FROM users WHERE state='$statename' ORDER BY petName ASC";
$pet = mysql_query($allpets);
while ($pets = mysql_fetch_assoc($pet)) {
echo "<a href='names.php?pet={$pets['memID']}'>{$pets['petName']}</a>, ";
}
}
?>

When I click on a name I get what I expect for a url but I don't have any data there >> I tried adding just this one thing after the end of the php above


<td><?php print $owner?></td>

as a test to see if it would print anything, but it didn't. Do I need to do an action to php self? or do I actually need a formatted page called 'pet' that the url will point to?

Thanks for any advice or a tutorial that shows a similar sample of how to do that.

Timotheos

6:28 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Meghanp,

Well first of all you'll need to have a names.php file.

The variable you're after will then be in the $_GET array as $_GET['pet'].

Once you've got that then follow the examples in this thread to get the rest of your data.
[webmasterworld.com...]

meganp

12:36 am on Mar 12, 2004 (gmt 0)

10+ Year Member



Hi, and thank you.

I created the names.php page and added the following code, but still get a page not found when clicking on the link. I guess I still don't understand how this works.


<?php
// Connect to the database
require_once ('../Connections/mysql_connect.php');
// Get the pet's name
if (isset($_GET[pet])) {
$query = "SELECT owner FROM users WHERE petID ='$petID'";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result)) {
// display owner information text
echo "$_GET['owner'];"
}
}
?>

What am I doing wrong?