Page 1 of 1

parameters store

Posted: Fri Sep 25, 2009 6:35 pm
by CLiFoS
hi,

I'm new to the forum and also new to php.
I'm a programmer, but not php and not web, so I understand programing, but just starting php so lots of concepts still missing.

I was googling for a way to stack parameters as the user clicks on the links in the page.

let me explain.

I have a table with user data from a db. So there are some links on the top that will filter the data like 'show all', 'registered users' and so on. also, in the table header there are links to sort the filtered data.

All links are working, but I don't understand how to make them work together, so a user can filter only registered users and sort them ascending from ID or email for instance.

Is there an easy way to do this in php?
how can I know what was the previous active parameters?
some parameters work with each other and other don't. how do I work this out?
if there is no 'easy' way, then how would the code flow should look like?

I have a login script with session, I believe that would be needed?

thanks in advance :)

Re: parameters store

Posted: Sat Sep 26, 2009 8:56 am
by CLiFoS
hi,
I noticed some ppl read my post but noone replyed.

I was wondering if its because its a stupid question or is it too difficult.

I dont want to full source code, just some pointers to the right way to implement it :)

thanks

Re: parameters store

Posted: Sat Sep 26, 2009 9:01 am
by Darhazer
I can suggest two approaches.
* Having a function that builds the link
You are passing the current variable to the function (e.g. sort by), and it appends the filtering parameters, that are currently active (which it retrieves the same way as the other script do currently to use them)
In this way your links will contain all parameters needed - filters, sort, page, etc
* Use sessions
I believe that you'll understand this approach as soon as you read the PHP manual on sessions

Re: parameters store

Posted: Sat Sep 26, 2009 3:23 pm
by Ollie Saunders

Code: Select all

<?php
/* Say: */ $_GET = array('xclude' => 'monkeys'); 
 
function GETParamsAsQueryStr($xtraParams) {
    $params = array_merge($_GET, $xtraParams);
    $accumulates = array();
    foreach ($params as $k => $v) { $accumulates[] = urlencode($k) . '=' . urlencode($v); }
    return '?' . implode('&', $accumulates); }
 
echo '<a href="' . htmlspecialchars(GETParamsAsQueryStr(array('fltRegUsrs' => 1))) . '">Filter Registered Users</a>';
In action:

Code: Select all

$ php tmp.php
<a href="?xclude=monkeys&fltRegUsrs=1">Filter Registered Users</a>

Re: parameters store

Posted: Sat Sep 26, 2009 5:35 pm
by CLiFoS
thanks guys,

you were most helpfull. :)