Jump to content

Easy question for PHP Pros


corrupshun

Recommended Posts

So I've decided to jump into the realm of flash game websites

Now what I've realized on most sites is one file called something like games.php

When you click the link to the game you want to play it would be like games.php?gameid=293

And this would have the same template as all the other games have but loads a different title and flash game.

I know that the ?gameid=293 is using php GET but how would I implement this? Would it take information from a database? I know I could make a VERY long conditional list but that's obviously the stupid way ;)

Is this possible without a database?

If possible please give some code..

Thanks LOTS!

-Aus

Link to comment
https://forums.phpfreaks.com/topic/182975-easy-question-for-php-pros/
Share on other sites

This sort of thing is not possible without a database. Whether it's a flat-file database or a Structured-Query-Language Database, you need something to store the information for the games in.

 

Also $_GET['id'] would be the I.D. of the row of the corresponding game in the database. So say you have an database table called `flashgames`:

`id`    `title`    `path`
  1     Game1     /games/1.swf
  2     Game 2    /games/foo.swf
  3     Game 3    /games/bar.swf

 

So in your table, `id` would be the automatically generated I.D. number of the row, `title` would be the title of the game, and `path` would be the file-path to the game-file (flash games are usually in .swf).

 

So then your script might look like this:

<?php
    $id = $_GET['id'];
    $query = mysql_query("SELECT `title`, `path` FROM `flashgames` WHERE `id`=$id");
    $row = mysql_fetch_assoc($query);
    echo $row['title'];
    echo '<br />'.$row['path'];
?>

 

So, with those dummy code snippets, if $_GET['id'] = 2, you'd see "Game2" followed by "/games/foo.swf" on the line below "Game2"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.