Results 1 to 3 of 3

Thread: help to filtering something

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help to filtering something

    Hy, i made the following code to filter something , its working but i dont know to make it work without the //// you will see if you run it this,

    http://localhost/test.php?f=FILTER1-A//////////
    http://localhost/test.php?f=FILTER1-...LTER4-B///////
    thanks and i hope u give me a hint
    PHP Code:
    <?php

    $string 
    $_GET['f'];
    $pieces explode("/"$string);

    $a = array(
    ''.$pieces[0].'',
    ''.$pieces[1].'',
    ''.$pieces[2].'',
    ''.$pieces[3].'',
    ''.$pieces[4].'',
    ''.$pieces[5].'',
    ''.$pieces[6].'',
    ''.$pieces[7].'',
    ''.$pieces[8].'',
    ''.$pieces[9].'');


    $sql "SELECT *  FROM `products` WHERE `FILTER` LIKE '%..%'""\r\n";

    $i 0;
    foreach (
    $a as $v
    {
        
    $sql .= "AND `FILTER` LIKE '%$v%'" "\r\n";
        
    $i++;
    }
    $sql .= ";" "\r\n";

    if(
    $pieces[0]==""){$f1 ="/";} else { $f1 "".$pieces[0]."/"; }
    if(
    $pieces[1]==""){$f2="/";} else { $f2 "".$pieces[1]."/"; }
    if(
    $pieces[2]==""){$f3="/";} else { $f3 "".$pieces[2]."/"; }
    if(
    $pieces[3]==""){$f4="/";} else { $f4 "".$pieces[3]."/"; }
    if(
    $pieces[4]==""){$f5="/";} else { $f5 "".$pieces[4]."/"; }
    if(
    $pieces[5]==""){$f6="/";} else { $f6 "".$pieces[5]."/"; }
    if(
    $pieces[6]==""){$f7="/";} else { $f7 "".$pieces[6]."/"; }
    if(
    $pieces[7]==""){$f8="/";} else { $f8 "".$pieces[7]."/"; }
    if(
    $pieces[8]==""){$f9="/";} else { $f9 "".$pieces[8]."/"; }
    if(
    $pieces[9]==""){$f10="/";} else { $f10 "".$pieces[9]."/"; }




    ?>
    <a href="?f=FILTER1-A/<?=$f2?><?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER1-A</a>
    <a href="?f=FILTER1-B/<?=$f2?><?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER1-B</a>
    <a href="?f=FILTER1-C/<?=$f2?><?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER1-C</a>
    <a href="?f=<?=$f1?>FILTER2-A/<?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER2-A</a>
    <a href="?f=<?=$f1?>FILTER2-B/<?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER2-B</a>
    <a href="?f=<?=$f1?>FILTER2-C/<?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER2-C</a>
    <a href="?f=<?=$f1?><?=$f2?>FILTER3-A/<?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER3-A</a>
    <a href="?f=<?=$f1?><?=$f2?>FILTER3-B/<?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER3-B</a>
    <a href="?f=<?=$f1?><?=$f2?>FILTER3-C/<?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER3-C</a>
    <a href="?f=<?=$f1?><?=$f2?><?=$f3?>FILTER4-A/<?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER4-A</a>
    <a href="?f=<?=$f1?><?=$f2?><?=$f3?>FILTER4-B/<?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER4-B</a>
    <a href="?f=<?=$f1?><?=$f2?><?=$f3?>FILTER4-C/<?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>">FILTER4-C</a>


    <?
    if($pieces[1]!=""){
    ?>
    <a href="?f=<?=$f1?>/<?=$f3?><?=$f4?><?=$f5?><?=$f6?><?=$f7?><?=$f8?><?=$f9?><?=$f10?>"><font color="red"><?=$f2?></font></a>
    <? ?>
    Last edited by c00sm1n; 04-02-2009 at 05:33 AM.

  2. #2
    Join Date
    Mar 2009
    Posts
    65
    Thanks
    13
    Thanked 4 Times in 4 Posts

    Default

    Not sure what is your intend, but you can pass an array through query string like this

    PHP Code:
    script.php?a[]=0&a[]=1&b[attempts]=0&b[userid]=1234 
    This saves all the filtering...

    And for the second part:

    PHP Code:
    $a = array(
    ''.$pieces[0].'',
    ''.$pieces[1].'',
    ''.$pieces[2].'',
    ''.$pieces[3].'',
    ''.$pieces[4].'',
    ''.$pieces[5].'',
    ''.$pieces[6].'',
    ''.$pieces[7].'',
    ''.$pieces[8].'',
    ''.$pieces[9].''); 
    How can you be sure that there are 10? better to count the number of elements in $pieces and do a loop.

    PHP Code:
    $a = array();
    for (
    $i 0; $ count($pieces); i++)
       
    a.push($pieces[i]) 
    You never did execute the sql. Is that relevant to the problem?

    PHP Code:
    if($pieces[0]==""){$f1 ="/";} else { $f1 "".$pieces[0]."/"; }
    if(
    $pieces[1]==""){$f2="/";} else { $f2 "".$pieces[1]."/"; }
    if(
    $pieces[2]==""){$f3="/";} else { $f3 "".$pieces[2]."/"; }
    if(
    $pieces[3]==""){$f4="/";} else { $f4 "".$pieces[3]."/"; }
    if(
    $pieces[4]==""){$f5="/";} else { $f5 "".$pieces[4]."/"; }
    if(
    $pieces[5]==""){$f6="/";} else { $f6 "".$pieces[5]."/"; }
    if(
    $pieces[6]==""){$f7="/";} else { $f7 "".$pieces[6]."/"; }
    if(
    $pieces[7]==""){$f8="/";} else { $f8 "".$pieces[7]."/"; }
    if(
    $pieces[8]==""){$f9="/";} else { $f9 "".$pieces[8]."/"; }
    if(
    $pieces[9]==""){$f10="/";} else { $f10 "".$pieces[9]."/"; } 
    Shouldn't the various $f variables be blank IF the pieces are empty?

  3. #3
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i dont think u understand, i want to make somethink like this , i have 4 filter for exemple , first filter have the variables (blue, green,red) , second (10cm,20cm,30cm) ..., and if i select the second filter to 30cm the link looks like ..script.php?filter=30cm/ , if i want the first filter and to keep the second the link should look like this script.php?filter=blue/30cm/ .. if i want to select the third filter and to keep the first and the second the link should look like this script.php?filter=blue/30cm/thirdfilter/ (blue - first filter, 30cm - second filter, thirdfilter - third filter) and so long .. and the option to remove a filter , if i want to remove the second filter the link should look like this script.php?filter=blue/thirdfilter/ , basicly i dont know how to make the link and to remove a variable from link, thanks for helping me and sorry for my english.
    Last edited by c00sm1n; 04-02-2009 at 08:56 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •