Alright. I don't know how to program in PHP. I don't currently want to know. All I want to know is if &= " and" then what = "or"?

I'm on a site with a search. the search doesn't work completly. The admin has much more important things to do then fix it. We can tweeak the search to fix the problems by adjusting the url. (note the admin is aware that we players sometimes add stuff to the url to get it to work right.)

Here is an example with the main words replaced for privacy:

Now this is supposed to return data sets where variables1 through 3 and variable 5 is anything and where variable 4 reads "Name1 Name2" However - this doesn't work. UNTIL I add another %25 like this: variable4=Name1%25Name2%25

Then it works. I'm guessing %25 is a wildcard?

Anyway this is just an example of what I'm talking about manipulating the url. I have no access to the program itself. I want to know if there is an "or " command. In other words if & = "and" what = "or" It may not work because she may not have programmed it that way but I want to try it.

One of the variables is a size variable. Instead of varable1=big&variable2= etc. I'd like to do varable1=big (or) large. Though that may be written varable1=big(symbol meaning "or") varable1=large&varable2= etc.

I hope I make sence here. I'm planning to write the admin to suggest how to correct the search for some of the other items... but I want to see if an "or" link is possible as well so I can suggest how to do another type of search.

thanks for your time.

Recommended Answers

All 3 Replies

Member Avatar for diafol

Alright. I don't know how to program in PHP. I don't currently want to know.

Sacrilege! You'll be lucky to get a reply after saying that!

Anyway, you can pass mutiple values for a parameter as an array:


HOWEVER - if the server-side code is not set up to deal with an array, just a single value or '%' separated values (that's your %25), then I don't expect this to work. It all depends on the way the code has been written to query the DB. Just because it works for one field ('variable' in your post above), doesn't mean to say it will work for every field. For example if variable1 was to do with 'image size', it's quite reasonable to expect a single input as ONE of big /medium / small. Using an array or '%' will not work to make an 'OR' clause for the database query.

Breaking the guy's SQL with certain characters in your url could work, but only if he's been lazy. That's not something I would recommend though.

At the end of the day, if the guy's not bothered, there's little you can do, but how about an online petition? Or calls to email en masse?

Thanks for the reply. Oh it's a game and I like it and pay for extras (it's free but you can support the game and get extra stuff.) I certianly don't want to break it!

Oh also I know older HTML and I'm self taught in my sql... but I'm not advanced. Just not interested in trying somethign else right now.

Anyway she introduced a number system - well it's been there but in the background... but she changed the way the game works a bit. It's hard for me to explane without giving away the game. Anyway she made some aspects harder so - she revelied the numbers. So now it's "big (16)" to show the range. We would like to have the search by the number. Because some of the ranges are rather large. So that's partially where the or came in. If she can do that with an array I'd love to pass that on to her. For example I'd love to search between 15 and 20. like if it was sql - where size between '15' and '20' Of course I don't expect to do that with the url - just you mentioning arrays got me thinking of it. I was hoping the (16) was part of the word so I could do a wild car but I don't think it is - I think it's stored seperate.

I just tried your idea - I wasn't sure if it was brackets or parenthsis. When I tried brackets I got nothing... when I tried parenthsis - I got everything. there isn't anythign that is supposed to go between them is there?

Member Avatar for diafol

there isn't anythign that is supposed to go between them is there?

Not as a rule, unless you need a associative array, which I'm pretty sure you don't.
You can pass arrays on to create SQL quite easily with a bit of php:


All the php needs to do is something like:

    $range = (array) $_GET['range'];
    $range = array_map("intval",$range);
    $rangestring = implode(",",$range);
    $sql = "SELECT ... FROM table WHERE range_id IN ($rangestring)";

However, you could just use a comma separated list of values:


Could be dealt with:

    $range = (array) $_GET['range'];
    $range = explode(",",$range);
    $range = array_map("intval",$range);
    $rangestring = implode(",",$range);
    $sql = "SELECT ... FROM table WHERE range_id IN ($rangestring)";

This may seem a bit involved, but it simply ensure that all incoming data is cleaned before querying the database.



Just re-read about 'between' - yes simple:


Could be dealt with:

if(isset($_GET['rangestart']) && isset($_GET['rangeend'])){
    $rangestart = intval($_GET['rangestart']);
    $rangeend = intval($_GET['rangeend']);
    if($rangeend >= $rangestart){
        $r1 = $rangestart;
        $r2 = $rangeend;
        $r1 = $rangeend;
        $r2 = $rangestart;
    $sql = "SELECT ... FROM table WHERE range_id BETWEEN $rangestart AND $rangeend";

To be honest there are many ways to go about this - you could even do an associative array:


That would be trivial for a moderately experienced PHP programmer to turn that to query to DB

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.