PHP - Generating Web Pages According To Database

Associate
Joined
19 Mar 2005
Posts
569
Just wondering if someone could point me in the right direction, I want to have a page which contains links to all of the people that are in my database. Then when you click on their name a new page opens with all of their information.

PHP:
	$query  = "SELECT playerID, playerName FROM players ORDER BY playerName";
	$result = mysql_query($query) or die('Error : ' . mysql_error()); 
	$content =  '<ul>';

	
	while ($row = mysql_fetch_assoc($result)) 
	{


	print "<li><a href=\"playerDetails.php?playerID={$row['playerID']}\">{$row['playerName']}</a></li>\r\n";

	  }
	
	$content .= '</ul>';

This is what I have so far, I want to know if this is correct for what I am doing and what needs to be on playerDetails.php for me to be able to able to show the details of the name just clicked.

Cheers

Leon
 
Have done the following below and get "invalid playerID number" . Have I implemented this correctly to get it to display the links to other players? Yes playerID is a unique numeric field which identifies each player. Then on playerDetails.php the field the page that displays the slected users data I just call $_GET["playerid"] in the sql query?
PHP:
		$playerid = $_GET["playerid"];
		
		
		if(preg_match("/^[\d]+$/",$playerid))
	{
	$query  = "SELECT playerID, playerName FROM players WHERE playerID = $playerid";
	$result = mysql_query($query) or die('Error : ' . mysql_error()); 
	$content =  '<ul>';
	while ($row = mysql_fetch_assoc($result)) 
	{
	print "<li><a href=\"playerDetails.php?playerID={$row['playerID']}\">{$row['playerName']}</a></li>\r\n";
	  }	
	$content .= '</ul>';
		}
		else
		{
		echo "invalid player ID number";
		}
 
Back
Top Bottom