Jump to content

heller

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

heller's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=markbett]read the values from the array and set them to a variable THEN write them back into the array[/quote] I tried everything: assigning and reassigning to variables, playing with different arrays extracting values with ereg_replace() instead of explode(), splitting strings in different ways etc. While hard-coded strings in any part of the script (e.g. 'blahblah' instead of $pair[1]) remain in $_SESSION forever unless unset or overwritten, but as soon as there [i]anything[/i] derived from $_POST, it vanishes in the thin air. [quote author=markbett]otherwise ensure you are writing to the correct key value in the array or else you will overwrite the information[/quote] Even if I messed up with the keys (which I didn't), the information should be overwritten with [i]another[/i] information, not just NULL's. [quote author=btherl]When you say "filled with three NULLs", do you mean that the array $_SESSION['filters'][filter] exists, and each element has value null?[/quote] Exactly. [quote author=btherl]I'm interested to see some var_dump()s of your $_GET, $_POST and $_SESSION .. surely there must be something different?[/quote] There we go. I'll show only the ['filters'] part of the $_SESSION, and I'll show it twice: before filter adjustment (the script in my original message) and after it. So I load the page with the table: [tt]$_SESSION['filters']: NULL $_GET: array(2) { ["section"]=> string(3) "rep" ["subsection"]=> string(3) "ind" } $_POST: array(0) { } $_SESSION['filters'] after adjusting: NULL [/tt] Then I choose 'last month' for the 'Date' column: [tt]$_SESSION['filters']: NULL $_GET: array(3) { ["section"]=> string(3) "rep" ["subsection"]=> string(3) "ind" ["dbtFilter"]=> string(4) "date" } $_POST: array(1) { ["ddlDate"]=> string(27) "min=2006-8-01&max=2006-8-31" } $_GET['dbtFilter']: string(4) "date" $_POST['ddl'.ucfirst($_GET['dbtFilter'])]: string(27) "min=2006-8-01&max=2006-8-31" $pairs: Array ( [0] => min=2006-8-01 [1] => max=2006-8-31 ) $options: Array ( [min] => 2006-8-01 [max] => 2006-8-31 ) $_SESSION['filters'] after adjusting: array(1) { ["date"]=> array(3) { ["choice"]=> NULL ["min"]=> string(9) "2006-8-01" ["max"]=> string(9) "2006-8-31" } }[/tt] Perfect, isn't it? Everything is seen, found, assigned etc. Okay. Now I go for 'Category' with the ID '1': [tt]$_SESSION['filters']: array(1) { ["date"]=>  array(3) { ["choice"]=>  NULL ["min"]=>  NULL ["max"]=>  NULL } } $_GET: array(3) { ["section"]=> string(3) "rep" ["subsection"]=> string(3) "ind" ["dbtFilter"]=> string(8) "category" } $_POST: array(1) { ["ddlCategory"]=> string(8) "choice=1" } $_GET['dbtFilter']: string(8) "category" $_POST['ddl'.ucfirst($_GET['dbtFilter'])]: string(8) "choice=1" $pairs: array(1) { [0]=> string(8) "choice=1" } $options: array(1) { ["choice"]=> string(1) "1" } $_SESSION['filters'] after adjusting: array(2) { ["date"]=> array(3) { ["choice"]=> NULL ["min"]=> NULL ["max"]=> NULL } ["category"]=> array(3) { ["choice"]=> string(1) "1" ["min"]=> NULL ["max"]=> NULL } }[/tt] Bang! Again, everything is seen and assigned, but the $_SESSION['filters']['date']'s three values (well, two)... Where the shining star are they? And, again: why are they in place in IE?
  2. Hi there! I've got a weird problem with a trivial piece of script... Googled and faqqed my brains off, but still nothing... There's a table displaying some data from DB. I'm using a drop-down list to set filters for certain columns, e.g.: [code] <form name="frmDate" method="post" action="/index.php?section=rep&subsection=ind&dbtFilter=date"> <select name="ddlDate" onchange="document.frmDate.submit()"> <option value="choice=all">all</option> <option value="min=2006-9-8">previous seven days</option> <option value="min=2006-9-01">this month</option> <option value="min=2006-8-01&max=2006-8-31">last month</option> </select> </form> [/code] As you can see, the name of the field to be filtered is sent by GET (dbtFilter) and the options (choice, min and/or max) are sent by POST. On receiving the page, I retrieve and save the whole lot in $_SESSION, so that multiple filters can be applied to the table, one by one. Here's the code chunk: [code] if (isset($_GET['dbtFilter'])) { // compose drop-down list name from field name // and extract filter option pairs (e.g. 'choice=123' or 'max=2006-09-10') $pairs = explode("&", $_POST['ddl'.ucfirst($_GET['dbtFilter'])]); // separate option keys and values foreach ($pairs as $pair) { $pair = explode("=", $pair); $options[$pair[0]] = $pair[1]; } // reset filter for this particular column - new data is here unset($_SESSION['filters'][$_GET['dbtFilter']]); // leave the filter empty if 'all' (no filtering) ist set, otherwise save new values if ($options['choice'] != "all") { $_SESSION['filters'][$_GET['dbtFilter']] = array( "choice" => $options['choice'], "min" => $options['min'], "max" => $options['max'] ); } } [/code] Thus, if I choose e.g. 'previous seven days' option for the 'Date' column, $_SESSION['filters']['date'] gets filled with data. Next, I choose e.g. 'John Smith' in 'Name', $_SESSION['filters']['name'] gets filled, too. I should have two active filters by now, right? Now, the problem: in the example above, after I choose 'Smith' (or whatever), previously set $_SESSION['filters']['date']'s three values ('choice', 'min', 'max') get NULLed, all three of them! Moreover, if I click [i]any[/i] link on the page (e.g. sort by some column), any filter's options set with a previous click get NULLed, too. After clicking around I end up with a $_SESSION['filters'][ALL_FILTERABLE_COLUMNS] each filled with three NULL's. I debugged the whole thing: it works big time until the very end of the script! The $pairs array is initialized, $options too, session dump shows that the data has been saved to a proper place and remained there until the end of the script. It just wouldn't persist until the page has been updated! After several experiments I discovered there was something wrong with the POST data. If I hard-code any string instead of $_POST['ddl'.ucfirst($_GET['dbtFilter'])], it works, the data doesn't get lost! But I can actually [i]see[/i] the value of $_POST['ddl'.ucfirst($_GET['dbtFilter'])]! It [i]does[/i] go to $_SESSION and activate its very filter on the page. I tried it on three machines with three different configurations - same result, but what a waste of time: today I found out that in IE everything works perfectly, the multiple filters are there! Anyone seen this before? Any ideas where I am being had by my favorite FF are very much appreciated.
×
×
  • 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.