Help please with PHP...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Help please with PHP...

Post by makisoustas »

I have a website and I am using an arcade script but I don't want to keep working on this. I want to make own script in the website. Anyway I want for example on the homepage to display thumbails of the games. When user clicks on a game he will be redirected to a page where the game will be displayed. Because I don't want to make a page for every game in html. I want with this only page to display the game that the user clicked from the homepage. How I'll do that?

Thank you!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

You can link to the page like this:

Code: Select all

http://example.com/game.php?game=somegame
Then access the value of ?game with $_GET['game']. In this case, the value of $_GET['game'] would be "somegame".
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:You can link to the page like this:

Code: Select all

http://example.com/game.php?game=somegame
Then access the value of ?game with $_GET['game']. In this case, the value of $_GET['game'] would be "somegame".
Do you mean put this on the homepage for example: <a href="http://example.com/game.php?game=somegame">(Here will be placed text or image of the game)</a> and in the game page I will place this: $_GET['game'] ?? How the game page will show the game? From the database and with the "echo ()" function??

And thanks for your reply!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

makisoustas wrote:Do you mean put this on the homepage for example: <a href="http://example.com/game.php?game=somegame">(Here will be placed text or image of the game)</a> and in the game page I will place this: $_GET['game'] ??
That's right.
makisoustas wrote:How the game page will show the game? From the database and with the "echo ()" function??
If that's where your games are stored, then yes.
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:
makisoustas wrote:Do you mean put this on the homepage for example: <a href="http://example.com/game.php?game=somegame">(Here will be placed text or image of the game)</a> and in the game page I will place this: $_GET['game'] ??
That's right.
makisoustas wrote:How the game page will show the game? From the database and with the "echo ()" function??
If that's where your games are stored, then yes.
Imagine you have games on database with code for everyone (embed for example). OK? The game page will show the game which the user clicked and it is stored in the database. Can you please write the code for homepage and for the game page? Please!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

The first step is to display all games on the home page. They way to do that is to select all items from your database table, and output them. Here's a tutorial on MySQL.

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

Could you tell us your table's schema (what columns it has)?
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:The first step is to display all games on the home page. They way to do that is to select all items from your database table, and output them. Here's a tutorial on MySQL.

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

Could you tell us your table's schema (what columns it has)?
I know to display the games from the database with php in the homepage. The database will be called games the table game and inside this table will be title,category,code,image. What is next?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

Do you know how to make the link properly?
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:Do you know how to make the link properly?
Do you mean the <a href></a> ??
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

Yes. The http://example.com/game.php?game=samegame thing.
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:Yes. The http://example.com/game.php?game=samegame thing.
I know good html but in php I am confused. Continue please to the next step...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

In your table, you'll also have a column called ID. When you list the games on the home page, echo the link with the ID in the url. Have you read the MySQL tutorial yet?
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:In your table, you'll also have a column called ID. When you list the games on the home page, echo the link with the ID in the url. Have you read the MySQL tutorial yet?
No but also I know to echo the id ok. But what is the code that will show the game that the user clicked? I haven't understand yet, sorry!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help please with PHP...

Post by Jonah Bron »

Okay, on the game.php page, you'll get the ID of the game the user clicked on with $_GET['id']. Then select the row from the database with that ID, and echo the code column. Done!
makisoustas
Forum Newbie
Posts: 12
Joined: Sat Dec 18, 2010 5:11 pm

Re: Help please with PHP...

Post by makisoustas »

Jonah Bron wrote:Okay, on the game.php page, you'll get the ID of the game the user clicked on with $_GET['id']. Then select the row from the database with that ID, and echo the code column. Done!
Ok thanks but which row from the database? I'm confused! :P
Post Reply