Jump to content


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


Trying to use a template to output from a database. Need help.

Recommended Posts

I saw the guidelines, but couldn't find the newbie section  ??? so I was hoping someone could help me.

Okay, here is what I am trying to accomplish. I have a template page made and I want to be able to pull from a MySQL database to output the page into the template. I've accomplished this already.

I am using the $_SESSION['name'] variable to pull the information I want from my database. Now, on the page prior that is going to take me to the game.php page. When the user clicks on the link, I want to define the $_SESSION['name'] as the name I want to pull. I tried using javascript onclick like so, but I didn't have any luck.

<a href="game.php" onclick="<?php $name="example 1"; $_SESSION['name']=$name; ?>">Example 1</a>

<a href="game.php" onclick="<?php $name="example 2"; $_SESSION['name']=$name; ?>">Example 2</a>

I guess JS is client side and PHP is server side so I'm going about this all wrong. Can someone point me in the right direction?

Thanks in advance.

Share this post

Link to post
Share on other sites
Yeah. I am pulling from my database with PHP and outputting it into a HTML template. My goal is to reuse the same template so I don't have to create a different page for every item in the database.

I would like to somehow define the $_SESSION variable as the item I would like to pull from the database. The problem I am having is I am using the same variable name and it always finds the 2nd one as it is the last one defined. I guess I am trying to figure out how I can use the same variable name, but only define it as what I am looking for if it is selected. Something along those lines.

Or, is there some other way I can pass the variable to the next page when the link is clicked or possibly pass the variable name in the link?

Share this post

Link to post
Share on other sites
Nevermind. I figured it out. I didn't realize I could put it in the URL and use the $_GET function on the next page.

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.


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.