mysql - How to Link PHP Sub Categories(Pages) Dynamically -
i have there php file getting data mysql database called:
clubs.php
 club.php
 player.php
the clubs.php list clubs tbleclubs table , looks like:
clubs.php
$database = new database(); $res = $db->query("select * tblclubs"); foreach ($res $datarow): ?>     <span><?php echo $datarow['id']; ?></span>     <span><a hrer=""><?php echo $datarow['name']; ?> </a></span> <?php endforeach; ?> and club.php listing players in club tblclub table
club.php
$database = new database(); $res = $db->query("select * tblpclub"); foreach ($res $datarow): ?>     <span><?php echo $datarow['id']; ?></span>     <span><a hrer=""><?php echo $datarow['name']; ?> </a></span> <?php endforeach; ?> and player.php tbleplayer:
player.php
$database = new database(); $res = $db->query("select * tblplayers"); foreach ($res $datarow): ?>     <span><?php echo $datarow['id']; ?></span>     <span><a hrer=""><?php echo $datarow['name']; ?> </a></span> <?php endforeach; ?> i have set foreign key(fk) tblclub clubs_id , tblplayers club_id.
now, question is, how can dynamically navigate each selected item in next page like:
clubs->club->player
thanks

ok, rendering static lists.
to make navigation dynamic need 3 things:
- create links ids
- fetch id url
- and query db using statement select specific id
you have started links: <a hrer="">, it's href.
clubs.php - render overview of clubs links each club
place in foreach construct links attaching ids.
foreach ($res $datarow) {     $id = $datarow['id'];     $name = $datarow['name'];     $link = 'club.php?id=' . $id;      echo '<span>' . $id . '</span>';     echo '<span><a href="' . $link . '">' . $name. '</a></span>'; } now can click instance club.php?id=2. club.php need handle incoming id, right?
club.php - renders list of players links each player
you repeat pattern above, different anchor base, time it's player.php. should list player.php?id=x links.
how handle id in each of scripts?
the id incoming via $_get. 
you can use var_dump($_get['id']) see value. use variable, $id = $_get['id']. 
(later, when works: not forget secure , escape incoming data properly.)
then use $id in database query:
select * tblplayers player_id = ' . $id;
Comments
Post a Comment