parameters store

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CLiFoS
Forum Newbie
Posts: 3
Joined: Fri Sep 25, 2009 6:18 pm

parameters store

Post 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 :)
CLiFoS
Forum Newbie
Posts: 3
Joined: Fri Sep 25, 2009 6:18 pm

Re: parameters store

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: parameters store

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: parameters store

Post 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>
CLiFoS
Forum Newbie
Posts: 3
Joined: Fri Sep 25, 2009 6:18 pm

Re: parameters store

Post by CLiFoS »

thanks guys,

you were most helpfull. :)
Post Reply