lukep11a Posted July 15, 2011 Share Posted July 15, 2011 Hi, on my site each user has their own account page, and on there is a section where private leagues are listed, the code below shows how I pick up which private leagues they are currently a member of. What I am trying to do now is place a link around the part echo $row['privateleaguename']; so that when they click it they go to a new page where all the users that are also a member of that league are listed. I think it would maybe require a dynamic link creating around but not sure. If anyone can tell me how this can be done or point me in the right direction it would be very much appreciated. <?php $query = "SELECT privateleague.privateleaguename, privateleague.privateleagueid, user_leagues.userid, user_leagues.privateleagueid FROM privateleague, user_leagues WHERE user_leagues.userid = '{$_SESSION['userid']}' AND privateleague.privateleagueid = user_leagues.privateleagueid"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo $row['privateleaguename']; echo "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/ Share on other sites More sharing options...
AyKay47 Posted July 15, 2011 Share Posted July 15, 2011 wouldn't necessarily need to be a dynamic link. What you can do is create a link with a querystring with the privateleguename value stored in it. On the page that the link links to will grab the querystring data and act accordingly, showing the names from your db of those that share the value of the querystring value...make sense? <?php $query = "SELECT privateleague.privateleaguename, privateleague.privateleagueid, user_leagues.userid, user_leagues.privateleagueid FROM privateleague, user_leagues WHERE user_leagues.userid = '{$_SESSION['userid']}' AND privateleague.privateleagueid = user_leagues.privateleagueid"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $league_name = $row['privateleaguename']; echo $league_name; echo "Click Here! <br /> <a href='test.php?league_name=$league_name' />"; echo "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/#findComment-1243180 Share on other sites More sharing options...
lukep11a Posted July 15, 2011 Author Share Posted July 15, 2011 Thanks for your reply, that sounds good but then how would I get all the users teamnames who are in each league to be displayed on the resulting page. I have put some code together, but it's not working, I don't know if it's something to do with bringing the variable $league_name through from the previous page? <?php $query = "SELECT * FROM privateleague, user_leagues, login WHERE privateleague.privateleaguename = '$league_name' AND privateleague.privateleagueid = user_leagues.privateleagueid AND user_leagues.userid = login.userid"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['login.teamname']; echo "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/#findComment-1243249 Share on other sites More sharing options...
jcbones Posted July 15, 2011 Share Posted July 15, 2011 You did make sure that you fixed the link to point to your test script right? <?php $league_name = (isset($_GET['league_name'])) ? mysql_real_escape_string($_GET['league_name']) : NULL; //grab league name passed in the GET array. if(empty($league_name)) { exit('Un-authorized personnel only!!!'); } //if the name is null, then kill the page before database call. $query = "SELECT * FROM privateleague, user_leagues, login WHERE privateleague.privateleaguename = '$league_name' AND privateleague.privateleagueid = user_leagues.privateleagueid AND user_leagues.userid = login.userid"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['login.teamname']; echo "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/#findComment-1243251 Share on other sites More sharing options...
lukep11a Posted July 15, 2011 Author Share Posted July 15, 2011 Sorry, but what do you mean by that? Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/#findComment-1243258 Share on other sites More sharing options...
lukep11a Posted July 15, 2011 Author Share Posted July 15, 2011 thanks to you both, it wasn't showing any teamnames to start with but then I changed echo $row['login.teamname']; to echo $row['teamname']; and now it works, don't really understand why that is though to be honest Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/#findComment-1243263 Share on other sites More sharing options...
mikesta707 Posted July 15, 2011 Share Posted July 15, 2011 thanks to you both, it wasn't showing any teamnames to start with but then I changed echo $row['login.teamname']; to echo $row['teamname']; and now it works, don't really understand why that is though to be honest This is because in general, the name of the key string in the resulting array you get from mysql_fetch_xxxx is the name of the column. You can change this by using the as keyword, and in certain very specific instances the above may be untrue. The fire part of "login.teamname" (the "login." part) is what table the column is part of in the query string itself, but doesn't hold in baring in the actual array that is generated from the result set. Quote Link to comment https://forums.phpfreaks.com/topic/242076-dynamic-links/#findComment-1243276 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.