Jump to content

Reordering URL parameters to keep them consistent using PHP?


ddcphpf

Recommended Posts

Hi,

 

Please excuse my lack of pre-existing knowledge on the matter; this is some prepatory work I am doing before I speak with my PHP developer (I just know I'll get farther if I go in with some background knowledge)

 

Here's the scenario:

 

Using our website's search engine you can build all kinds of different URLs (we have many parameters)

 

In some cases you can create the same set of parameters but the order of them can vary, producing the same content but with different URLs (not desired)

 

What I'd like to do is recommend that we assign a placement hierarchy to the parameters so that we can be assured that if we're showing a particular set of results, the URL will always be the same, i.e. they will reorder themselves or "get in line" :happy-04:

 

Is this totally out in left field? Or is it doable?

 

I would also really appreciate any hints or examples that I can share with my developer to lead him in the right direction

 

Thanks very much :happy-04:

 

 

Link to comment
Share on other sites

i dont see why you cant do something like order them alphabetically.  throw them into an array first and then sort:

<?php sort( $array ); ?>

http://uk.php.net/manual/en/function.sort.php

 

once you have your items sorted, loop through the array to create your string.

 

if you want to maintain the key/value relationship such as in an associative array, use asort() instead.

Link to comment
Share on other sites

name your parameters alphabetical or numerical order as to the order in want to display them

?1something=1&3something=3&2something=2

?asomething=1&csomething=3&bsomething=2

 

then use something like this

 

 

<?php
if (isset($_REQUEST)) {
   
    ksort($_REQUEST);
   
    $build = array();
    foreach ($_REQUEST as $key => $value) {
        $build[] = $key . "=" . $value;
       
    }
   
    $new_query = implode("&", $build);
   
   
    echo $new_url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING) . "?" . $new_query;
   
}
?>
Link to comment
Share on other sites

Is other ways to go about this, like checking the key values and sorting in your own orders by key numbers, but have to check if they even exist, associate which ones to what order, can get messy.

 

another option is to just send all the possible GET parameters back even if they are empty in the order you want

 

can check if the $_REQUEST for each even exists and trim them as well,do any checking before place into query

$new_url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING) . "?article=" . $_REQUEST['article']."&id=".$_REQUEST['id']."&page=".$_REQUEST['page'];
Edited by QuickOldCar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.