简体   繁体   中英

How can I display information on a page that doesn't physically exist?

I've made my search form with html and jquery. When I input a name into the search field, and click search, it checked the MySQL database i specified, and displays any names containing the text in the search field. the url is localhost/players.html because I'm testing it on apache at the moment, and its for a game server player statistics page.

I have the results showing how I want them, in a table with certain information displayed in the columns.

When a result is clicked, I want to display the players statistics on a new page, but I don't want to create and store thousands of pages one for each registered player. So I want it to create a virtual page, or something like that. Where the link is clicked, the URL would be something like /players/PlayerName.html or if that isn't possible maybe players.php?action=getstats(PlayerName) I'm not really sure how to do this or if it's possible.

I want it to work so that if I was to type www.myurl.co.uk/players/PlayerName.html it would show the statistics page for that player, without the html page actually e xisting.

Do it like this

Create one page called "player.php", this page will receive parameter UserID.

So in you high score table add link for each player to point to this page with the parameter UserID

<a href="/player.php?player_id=xxxxx">Player</a>

when clicked it will go to player.php and you can get your parameter through global $_GET variable like this

$player_id = $_GET["player_id"]

So in you page just select data for that user

$sql = "select * from player_stat where UserID = " . $player_id;

just remember to mysql_escape $player_id before adding it to query in order to avoid SQL Injection

That is easy way, you can do it also with the URL rewriting apache module in order to get friendly URLs like /player/stat/nick-name

but that is more work if your system doesn't support this.

you need to use PHP for this

for example you will send each result to player.php?id=PLAYER_ID and on that page you need to get that player info from the db using the requested ID

check the following links to make it easier for you

http://www.w3schools.com/php/php_mysql_intro.asp

http://www.w3schools.com/php/php_get.asp

This is done using mod_rewrite, which is a module for rewriting URLs according to patterns. You often enter these patterns into a file called ".htaccess" file which you put in your web root.

For example:

RewriteEngine on
RewriteRule ^players/([^/]+).html.zip /search.php?playername=$1 [L]

If you go to "/players/MikeRoberts.html", then your PHP script "search.php" will receive the value "MikeRoberts" (which you can access using $_GET['playername']).

Remember: you may need to enable mod_rewrite on your server. See: How to enable mod_rewrite for Apache 2.2 or use Google to find out how to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM