Forum Moderators: coopster

Message Too Old, No Replies

Session variables and hyperlinks!

         

parisa

11:59 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Hi,
I'm having real problem! I am developing a site using php. In mycode, there's a table which is filled using a loop
that has a mysql connection as its parameter:

while ($row==mysql_fetch_array($myquery,$myconn)) {
...
}

within this loop I have hyperlinks and I want to send a new sssion variable with its value depending on the row of
the table which is chosen! how can I assign a value to a session variable within a hyperlink of <a href=...>...</a>
?

I will put the code here for you to have a look at! I am very desperate and in a real hurry!

this is the code of this part:

while ($row = mysql_fetch_array($locationq, MYSQL_NUM)) {
$_SESSION['site']=$row[0];
echo "<tr align=\"left\" valign=\"middle\">";
echo "<td>".$row[1]."</td>";
echo "<td height=\"100%\">&nbsp;</td>";
echo '<td nowrap valign=\"top\"><a href=systems.php?site=' . $row[0] . '>' . $row[2] . "</a></td>";
echo "<td height=\"100%\">&nbsp;</td>";
.
.
.

this is obviously wrong! Because in each iteration of the loop the value is changed!

I am trying the $_GET variables but this has made problems in the session! in the next page, the queries are not
working properly and I guess it's because of the $_GET variable used!

Any help would be appreciated!

BR

SeanW

12:13 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



It looks like you're setting the session variable to the same as what's beeing passed to systems.php.

Why not set the session variable in the beginning of systems.php, after the user has clicked? ie

$_SESSION['site'] = $_GET['site']

Sean

parisa

12:19 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



actually I did do that!

But now the queries using $_SESSION['site'] do not work properly! I can not see whatever I am supposed to be seeing there!

jatar_k

4:48 pm on Sep 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld parisa,

Are you sure you did as Sean mentioned?

if you take this out of your loop
$_SESSION['site']=$row[0];
as you have noticed if this is in the loop it will make the session value equal to the last iteration of the loop.

If you leave this
systems.php?site=' . $row[0] . '

then on your systems.php page set the site value from $_GET to the session like so
$_SESSION['site'] = $_GET['site']
then you will have the proper session value in the targetted script.

parisa

5:08 am on Sep 7, 2005 (gmt 0)

10+ Year Member



Yes actually I have exactly done the same! so may be the problem is somewhere else in the code! Because within the systems.php the queries are not working fine! The only possible reason I could think of was some sort of conflict between the session and using $_GET variables! Obviously there is not such a conflict, because you are telling me to do the same thing! So it seems that I should look for another reason!
Thank you all!
And thank your welcome note! :)

parisa

7:08 am on Sep 7, 2005 (gmt 0)

10+ Year Member



Hi!

There is another possible problem I found in my code!
This is the code:
$locationquery = " SELECT user_site.site_id, site.Client, site.site_name FROM `user_site`, `site` WHERE user_site.user_name='$_SESSION[username]' and site.site_id = user_site.site_id" ;
$locationq = mysql_query($locationquery , $conn);

$locationdailycolorquery = " SELECT user_site.site_id , Count(*) Cnt
FROM `probe_kpi`,
`system_probe` ,
`system`,
`user_site`
WHERE probe_kpi.date = '$_SESSION[startdate]'
AND probe_kpi.kpi_id = 1
AND probe_kpi.probe_id = system_probe.probe_id
AND ((system_probe.system_id = system.system_id
AND system.site_id = user_site.site_id)
AND (user_site.user_name = '$_SESSION[username]'))
AND probe_kpi.kpi_colour = 'RED'
Group By user_site.site_id";

$locationdailycolor = mysql_query($locationdailycolorquery, $conn);

while ($row = mysql_fetch_array($locationq, MYSQL_NUM)) {
echo "<tr align=\"left\" valign=\"middle\">";
echo "<td>".$row[1]."</td>";
echo "<td height=\"100%\">&nbsp;</td>";
echo '<td nowrap valign=\"top\"><a href=systems.php?site=' . $row[0] . '>' . $row[2] . "</a></td>";
echo "<td height=\"100%\">&nbsp;</td>";
$row1 = Mysql_fetch_array($locationdailycolor, MYSQL_NUM);
***if ($row1[$row[0]][1]>0) *** {
echo "<div id=\"MyLayer\" style=\"position:absolute; width:229px; height:62px; z-index:1; left: 43px; top: 46px; display:none\"></div>";
echo "<td nowrap valign=\"middle\"><a onClick=\"javascript:Show('Your text goes here! ');\" href=\"#\"><img src=\"images/red.bmp\" border='0'></a>";

}
.
.
.

I have put stars on the part I have problems! Is it ok to do so?

Can we use it this way? May be this is the cause!

coopster

2:14 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Answered in new post ...

[webmasterworld.com...]