Jump to content

Dynamic Links?


lukep11a

Recommended Posts

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

	?>

Link to comment
Share on other sites

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

	?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.