So say I have a list, Pet ID; 1. Jimmy 2. Alvin 3. Spot 4. Snowy 5. Bob How do I make PHP know the id of the pet and then open that file. So if the user clicked on the number 1 it would open that profile. NOTE: These numbers can change so doing it with HTML isn't an option, I can't do <a href="includes/profile_1">1. Jimmy</a> How do I do this?
where do you get the IDs from? They must come from somewhere? Just use the id-variable in the link? Or, better, rethink your project, and rethink the way you pull information.
Ok, sorry. I should have gone into more depth. Basically I'm displaying information that I have in a database. I want to be able to allow the user to click on the id number and then it'll open a page displaying the pets info. So, I'd have a database of pet's. I'd then display them on a page. If a user wants to click on a pet if it would bring up a profile page about the pet. Does that explain it better?
Yes, that was sort of what I figured - but I'm failing to see how the IDs will change? What you need to do is pull the information from the database for the pets in question - whether or not that's the user's pets, or just a collection of all pets, or whatever. These pets will have a unique ID (or, at least, they should), in the database - just use that in the link? Something like this: //assuming that you're pulling the info and running this with a while-loop echo '<ul>'; while ($row = $stmt->fetch()) { $id = $row['id']; $petname = $row['petname']; echo '<li><a href="includes/profile_'.$id.'">'.$petname.'</a></li>'; } echo '</ul>'; Code (markup): That should do exactly what you want, really.
Hi. This code dn't have database. Only pass Id and get your Page... try this code <a href="index.php?id=1"/>1. Jimmy</a> <?php if($_GET['id']==1) { ?> <a href="includes/profile_1"/>Jimmy</a> <?php } ?>
Jeez... How about: <a href="index.php?page=1">1. Jimmy</a> <?php if (isset($_GET['page'])) { include ('includes/profile_'.$_GET['page'].''); } ?> PHP: which would actually GET the content of the file, instead of printing another link to something ...