| | |
Dynamically creating $_SESSION variables
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi there
I'm having a bit of a problem. As the title suggests, I'm creating $_SESSION's such as dynamically which is working perfectly, but the problem is I don't know how to call that same variable on a template page that I click through to.
At the moment I have the following:
Clearly this isn't working because the session variable could be any of the id's pulled from the database on the previous page and therefore the template page shows no content. I need some way of tying the variable from the previous page to the variable on the template page without using symantic URL encoding.
I'm having a bit of a problem. As the title suggests, I'm creating $_SESSION's such as
php Syntax (Toggle Plain Text)
$_SESSION[''.$row[0].'']
At the moment I have the following:
php Syntax (Toggle Plain Text)
$query = "SELECT eid, title, content, image, image2 FROM diary WHERE eid = '".$_SESSION[''.$row[0].'']."'";
Last edited by Venom Rush; Feb 6th, 2008 at 7:14 am.
This user has a spatula. We don't know why, but we are afraid.
Why dont you assign the value to a variable and then use that variable ?
Eg.
Eg.
php Syntax (Toggle Plain Text)
<?php //page1.php session_start(); $_SESSION['eid']="1234"; // rest of your code... ?> <?php //page2.php session_start(); $eid=$_SESSION['eid']; $query = "SELECT eid, title, content, image, image2 FROM diary WHERE eid ='$eid'"; // rest of your code ?>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
•
•
Why dont you assign the value to a variable and then use that variable ?
Eg.
php Syntax (Toggle Plain Text)
<?php //page1.php session_start(); $_SESSION['eid']="1234"; // rest of your code... ?> <?php //page2.php session_start(); $eid=$_SESSION['eid']; $query = "SELECT eid, title, content, image, image2 FROM diary WHERE eid ='$eid'"; // rest of your code ?>
php Syntax (Toggle Plain Text)
<?php //page1.php session_start(); // some code //create query $query = "SELECT eid, title, SUBSTRING(content, 1, 200), thumb_image FROM diary ORDER BY eid DESC"; // some more code while($row = mysql_fetch_row($result)) { if (!$_SESSION[$row[0]]) { $_SESSION[$row[0]] = $row[0]; } //echo output here } // rest of your code... ?>
Last edited by Venom Rush; Feb 6th, 2008 at 7:35 am.
This user has a spatula. We don't know why, but we are afraid.
•
•
•
•
How are you differentiating between different links ? Say you have 4 links ? Arent you passing some id for different links ?
http://www.sitename.com/template.php?eid=38
All I want people to see is:
http://www.sitename.com/template.php
This user has a spatula. We don't know why, but we are afraid.
I dont think so. hmmm.. There is a weird way of doing it (which I wouldn't prefer). I hope you are looping to print the urls. What you can do is, use onclick event, set $_SESSION[$row[0]] value to a hidden variable and submit the form. 
As I said, this is the 'worst' way of doing it
. But if you dont want to attach the info to the url, then you can do it this way ! I haven't tested the code(maybe the code wont even work!). Just giving you an idea on how it might work.
Cheers,
Naveen

php Syntax (Toggle Plain Text)
<html> <body> <?php //connection //select db $query="select eid from table"; $result=mysql_query($query); while($row=mysql_fetch_array($result)){ echo "<form method=\"post\">"; echo "<input type=\"hidden\" name=\"eid\">"; echo "<a href=\"#\" onclick=\"javascript: document.form.eid.value='$_SESSION[$row[0]]'; document.form.action=\"template.php\"; document.form.submit();\">"; } ?>
As I said, this is the 'worst' way of doing it
. But if you dont want to attach the info to the url, then you can do it this way ! I haven't tested the code(maybe the code wont even work!). Just giving you an idea on how it might work.Cheers,
Naveen
Last edited by nav33n; Feb 6th, 2008 at 8:04 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
You can have an array of all the eids and put it in a session. Then, everytime a user clicks on a link, check whether the eid is in the array of eids. If its present, then display respective page. Else, send the user to "you know where" ! Also, use mysql_real_escape_string or addslashes.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Other Threads in the PHP Forum
- Previous Thread: Website Problem
- Next Thread: Showing images from mysql
| Thread Tools | Search this Thread |
advanced apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert ip javascript job joomla js limit link login mail menu mlm mobile multiple mysql oop outofmemmory paging parse password paypal pdf php problem procedure query radio random recursion remote return script search server sessions smarty sms source space sql stored syntax system table traffic tutorial unicode up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube






