Hi,

I'm building a website containing small games (swf-files).
I have created a table in MySQL called "games".
Inside this table are the fields "id" (with auto_increment), "address" (url to the swf-file) and "manual" (description of the game in text).
I've also made a function to load the swf-file in an iframe.

Now I'm a bit stuck.
I want people to be able to click on a link of a game, go to "gamewrapper.php" on which the iframe with the game is loaded. "gamewrapper.php" should be the only "game-playing page" (so that i don't have to create a different page for every game).

But how do I go from this to the hyperlinks of the games?
What should the hyperlink be? Could I use my table (field "id") for this?
like "gamewrapper.php&id=3"?
And if yes, do I need to change my script or anything?

This is my script so far:

<html>
<head>
<title> PHP Workshop 4 - testDb.php </title>

<?php
$db = mysql_connect("localhost","username","password") or die("Unable to connect to MySQL");
mysql_select_db("user_db",$db) or die("Unable to select database");

$query = mysql_query("SELECT address FROM games");
$row = mysql_fetch_array($query, MYSQL_ASSOC);

  echo "<a href='{$row['address']}'>Click me!</a>";
  echo "<iframe src='{$row['address']}' alt='' />";

?>

</head>
</html>[/I]

    hello

    if you are using a database and want to display a game in a page , you need to read more about

    GET
    POST
    REQUEST
    and fetch array

    this will help you

    GET method is the one that you will need ( as far as i know ) but make sure you know how to validate the data before using them

    in ur url
    gamewraper.php?gameid=1

    to make this is the page that show the ( game 1.swf ) you need use get to read the url

    so in gamewraper you can add something like

    MAKE ALL YOUR LINKS TO gamewraper.php?id='.$row['gameid'].'

    
    // make a variable with the data from the url which is gameid=1
    webgameid= $_GET["gameid"];
    
    // now webgameid=1 whcih was in the url 
    
    // now connect to the database , and select the databse 
    
    // now get the game data from the database
    $query = mysql_query("SELECT address FROM games WHERE ('gameid ==$webgameid')")
    
    // the above if no syntax error , selected the game address from the database and only the game that the id of it is what we get from the url 
    
    // fetch the db into array 
    
    echo $row['address']; 
    // this will echo the link , u can put the html code for flash and the source is that link 
    
    // now you have the gameid=1 address displayed , 
    
     

      hello

      so you need to do 2 things , i am noob dont follow what i write but follow the way it should be working

      all ur links from other pages to the game should be like this

      gamewraper.php?id='.$row['gameid'].'

      and in the gamewraper.php add to select statment the WHERE gameid

      make gameid = to the variable or you can use

      ID = '.$HTTP_GET_VARS['id']

      the http vars thing will read what in the url ( the game id )

      make sure no one can pass something bad ... bad ppl can add soemthing bad to ur url , and delete things or add things ...

      make a validation tool , whenre you check what kind of data is in the id= , numbers or some stuff with comma ... and harmful things that ppl can use

      also make sure you can add slashes or strip slashes so you have good results and secure ones

      thanks

        thanks for your replies!
        I'm new to php and mysql, in fact, that little script is my first one!
        So I can't help you with the user-script (I would like to know myself 😛 )
        But you've helped me out alot, now I know what I should be looking for in tutorials.
        Function Get will be the first i'll read about.
        Thanks!

          Write a Reply...