Page 2 of 2

Re: how to make 'games.php?id='

Posted: Mon Apr 11, 2011 6:00 pm
by Netroxy
Just to mention, I am using a web host provider, with database access to my own tables that I create. I'm not ready to use SSH for this because I don't know much about that. I did however create the database properly and it does have its host name, username and password, and the ID column is set to primary key.

Re: how to make 'games.php?id='

Posted: Tue Apr 12, 2011 2:40 pm
by danwguy
all of everything will be one page, just use an if statement to see if someone clicked a link to a game, and if not echo the links to the games. i.e...

Code: Select all

<?php
if(isset($_GET['id'])) {
$conn = mysql_connect("host", "username", "password");
mysql_select_db("games");
$game_id = $_GET['id'];
$sql = "SELECT * FROM games WHERE id='$game_id' LIMIT 1";
$result = mysql_query($sql, $conn) or die(mysql_error());
$number_of_results = mysql_num_rows($result);

while ($result_array = mysql_fetch_array($result, MYSQL_ASSOC)) {

$id = $result_array['fldID'];
$title = $result_array['fldTitle'];
$iconsmall = $result_array['fldIconSmall']; // Example: game1234.png
$swf = $result_array['fldSwfSrc']; // Example: game1234.swf
$iconsmall_file_location = 'http://www.blabla.com/games/images/' . $iconsmall;
$swf_file_location = 'http://www.blabla.com/games/' .$swf;

echo '<a href="http://www.blabla.com/games.php?id=' . $id . '"></a>';
echo '<h1>' . $title . '</h1>';
echo '<img src="' . $iconsmall_file_location . '" width="50" height="50" border="0" />';
echo '<object width="550" height="400">';
echo '<param name="movie" value="' . $swf_file_location . '">';
echo '<embed src="' . $swf_file_location . '" width="550" height="400">';
echo '</embed>';
echo '</object>';
}
} else {
//this is where you put the code to echo all of the game urls so that everything is done in one page example...
$sel2 = mysql_query("SELECT * FROM games");
 if(!$sel2) {
    echo "sorry could not get list of current games: " .mysql_error();
    exit();
    }
 while($row = mysql_fetch_assoc($sel2)) {
    echo "<br />Play " .$row['title']. "<a href='index.html?id=".$row['id']."'>Here</a>";
    }
}
presuming your database table is set up with title as the name of the game, if not just change the SELECT statement to select from the proper table and the $row['whatever'] to the proper names of the rows in your table. granted the last part is really simplistic and you probably want to add onto it, it's just an example so you can have everything in one page.

Re: how to make 'games.php?id='

Posted: Wed Apr 13, 2011 9:36 am
by Netroxy
Thanks to mecha_godzilla and you, it works.