Jump to content

one line of syntax. Why is this not correct?


alvarito

Recommended Posts

 

 

Hello,

 

still wrestling with the code I am afraid...

 

I am trying to pass this value $_SESSION['activity'] to the next page but I fail in both syntaxes

 

There are two ways I am trying:

 

1) echo "<td>" . "<a href='". "Templates/detailsession.dwt.php?ida=" . urlencode($daten['ida']). "&sid= " . session_id() . $_SESSION['activity'][/color] . "'>linktext</a>". "</td>";

 

 

<input type="hidden" name="sid" value="$_SESSION['activity']">

I do believe that trying to attach the sessionid to a url is basically obsolete anymore. PHP and Apache are setup to automatically pass it the session on through cookies. If the user does not allow cookies they usually attach the id onto the url. A good way to test this is change your browser to not allow cookies and see what it does.

 

http://www.mtdev.com/2002/06/why-you-should-disable-phps-session-use_trans_sid

 

Good reading if you have not already read it.

 

Next time please use the (code) (replace the paran with [ and ] tags) to put in code so it doesn't get all messed up.

 

 

To answer the question, this should work, looks like there was a few syntax errors and you did not really echo out the form field.

<?php
echo "<td>" . "<a href='Templates/detailsession.dwt.php?ida=" . urlencode($daten['ida']). "&sid= " . session_id() . $_SESSION['activity'] . "'>linktext</a>". "</td>";


echo '<input type="hidden" name="sid" value="' . $_SESSION['activity'] . '">';
?> 

Thank you very much to you all. All feedbacks were enlightening. I started learning what session was yesterday.

 

The scheme is:

 

1.Search form---------->2. Results list page-------------> Click on it and get detailed info for every row you

 

click----->3. Detail page---------------->Now I want to go back to page (2) (Result list data are gone) that

 

is the problem. That is, the user might want to see more results from page 2, but they are gone.

 

 

As per the comment:  that it is better to use cookies, yes I agree now. I am tired about appending dot and single quotes at every link. If the user doesnt want cookies I wont care, he should want to have them to make my life easier.  So I would prefer not to have to worry about those things. However, passing the values of the session variables looked (in my limited knowledge) like the only way to solve the problem that I mention elsewhere: I get tabulated data from a DB query after a search form use. Out of that tabulated data, i get results with links to a detail page for every row. Now the problem: if I want to return to the Results list page of the tabulated data...the data is gone. They were created by the Posted variables from the Search Form, but because I am not coming from there anymore, my data does not get regenerated. So I thought of passing and passing those variables through all the pages to resend them to the page where they get recreated.

 

As per the comment: that if they are session variables why dont just live them there? I wish, I knew how could that help me to recreate the data.

 

 

One question, does your query use the LIMIT feature so you will only pull the results you want?

 

It sounds like you are trying to store all the results in session, this is not recommended too much data to pass over the session and chances are it won't pass through. What most people do is something like this:

 

<?php
// assuming there is a db connection

$page = 0; // set default
$numResults = 20; // the number of rows you want returned

// This will set the offset with the pages to return the paged results
if (isset($_GET['page'])) {
   $offset = $_GET['page'] * $numResults; 
}else {
   $offset = 0; // first page start at 0
}

$sql = "SELECT * FROM table_name WHERE parameter=here LIMIT " . $offset . ", " . $numResults;

// do the data retrieval here
?>

 

That is a rough example but if you want a more working/thorough one there are a bunch online just google mysql paging

 

 

Thank you again a lot. I didnt know that session variables were not meant to carry lots of data through pages. So if I correctly understand, I should use standard variables for that purpose while one would use session variables for things like storing login and pwd or items in a shopping cart or so. I was unaware of what I could or should do with session variables.

 

thank you, merci, grazie, gracias, danke, bedankt, spasivo, obrigado.

 

Alvaro

 

 

 

 

 

One question, does your query use the LIMIT feature so you will only pull the results you want?

 

It sounds like you are trying to store all the results in session, this is not recommended too much data to pass over the session and chances are it won't pass through. What most people do is something like this:

 

<?php
// assuming there is a db connection

$page = 0; // set default
$numResults = 20; // the number of rows you want returned

// This will set the offset with the pages to return the paged results
if (isset($_GET['page'])) {
   $offset = $_GET['page'] * $numResults; 
}else {
   $offset = 0; // first page start at 0
}

$sql = "SELECT * FROM table_name WHERE parameter=here LIMIT " . $offset . ", " . $numResults;

// do the data retrieval here
?>

 

That is a rough example but if you want a more working/thorough one there are a bunch online just google mysql paging

Archived

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

×
×
  • Create New...

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.