Filter query with multiple URL parameters

Hi,

I have several categories in my DB each with an ID number.

Using a DB query how can I show the results of a combination of categories using a URL parameter request?

Example would be;
www.domain.com/category.php?cat_id=1&cat_id=2&cat_id=3

Do I need to use the multiple check box on the $_Get filter?

Many thanks
CK

Which part is not clear for you - how to add the filters in the url or how to filter the database query using the filters in the url?

I think the URL string is correct so I need to know how my database query should look in order for this to work.

Well, you need to define GET variable per each URL param and pass its value to the filters in the query builder, depending on your needs. It follows the same logic https://docs.wappler.io/t/filtering-database-query-with-an-url-parameter/2868

I see, I thought there might be a way to make the DB query accept multiple URL inputs to just a single filter.
I may as well just create a query with all the categories I need and not bother with the URL parameters.
I was looking for something more dynamic…

Well if you want to use a single url param with multiple values, then just use it like:

www.domain.com/category.php?cat_id=1,2,3

and split its value on the server side, to receive an array with the cat_id to be used in the filters.

Can you suggest a tutorial on how to;

‘split its value on the server side, to receive an array with the cat_id to be used in the filters’

Just apply the split formatter to the &_GET.param_name when used in the filters.

Use a checkbox array and a SQL IN clause in your SELECT query

Tried your split value suggestion but get no result. When I inspect the page I have an error:

Failed to load resource: the server responded with a status of 404 ()
https://mydomain.com/dmxConnect/api/Categories/CategoriesAllBindery.php?cat_id=1%2C2

URL was https://mydomain/dmxConnect/api/Categories/CategoriesAllBindery.php?cat_id=1,2

The split code looks like this:
$_GET.cat_id.split(’,’)

The 404 error means the file is missing from your server.

My easy way is check what is missing. You should find in your chrome dev tools, 2 buttons for warning and alert, the red one tells you what is missing.
I reccomend you to reupload the file.

Re-published my site and I now get the following error;

Failed to load resource: the server responded with a status of 500 ()
https://mydomain.com/dmxConnect/api/Categories/CategoriesAllBindery.php?cat_id=1

If I follow the link above the page loads with the following error;
A server error occurred, to see the error enable the DEBUG flag.

If I enable Debug on the DB query the original page;
https://mydomain.com/category-all-bindery.php?cat_id=1
loads but with just three blank records. If I load the api page I get a page thats loads what looks like JSON info.

You should not enable the debug option on the query step! This should be off.

You need to enable this:

1 Like

OK, thank you
Have turned on the debug and get the following error in the inspect tab:

Failed to load resource: the server responded with a status of 500 ()
https://mydomain.com/dmxConnect/api/Categories/CategoriesAllBindery.php?cat_id=1%2C2

That page now shows;
// 20220620092124
// https://mydomain.com/dmxConnect/api/Categories/CategoriesAllBindery.php?cat_id=1%2C2

{
“code”: 0,
“file”: “/var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/lib/db/Connection.php”,
“line”: 141,
“message”: “Array to string conversion”,
“trace”: “#0 [internal function]: exception_error_handler(8, ‘Array to string…’, ‘/var/www/vhosts…’, 141, Array)\n#1 /var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/lib/db/Connection.php(141): PDOStatement->bindParam(2, ‘Array’, 2)\n#2 /var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/modules/dbconnector.php(93): lib\db\Connection->execute(‘SELECT * FROM `…’, Array, true, ‘’, Array)\n#3 /var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/lib/App.php(197): modules\dbconnector->select(Object(stdClass), ‘query’, Array)\n#4 /var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/lib/App.php(137): lib\App->execSteps(Object(stdClass))\n#5 /var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/lib/App.php(126): lib\App->exec(Object(stdClass), false)\n#6 /var/www/vhosts/mydomain.com/httpdocs/dmxConnectLib/lib/App.php(104): lib\App->exec(Object(stdClass))\n#7 /var/www/vhosts/mydomain.com/httpdocs/dmxConnect/api/Categories/CategoriesAllBindery.php(8): lib\App->define(Object(stdClass))\n#8 {main}”
}

Post some screenshots of the query setup please.

With the split value you need to use IN, not Equal.

Brilliant, worked first time - of course.

Thank you @Teodor once again.