Jump to content


Photo

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


  • This topic is locked This topic is locked
4 replies to this topic

#1 livepjam

livepjam
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 24 September 2006 - 06:29 AM

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.



#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 08:44 AM

Are you trying to use a html template ?

#3 livepjam

livepjam
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 24 September 2006 - 05:31 PM

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?

#4 livepjam

livepjam
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 24 September 2006 - 09:20 PM

*bump*

#5 livepjam

livepjam
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 25 September 2006 - 01:22 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users