What's new

Welcome to xCrud Community - Data Management and extended PHP CRUD

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Dropdown Select Filter

SamTanner

New member
Joined
Mar 15, 2023
Messages
1
Reaction score
0
Points
1
Location
USA
I'm learning to write php code, so please excuse my errors.

Say I have two mysql tables... 'categories' and 'details'.
The 'categories' table only has two fields 'cat_id' (int, pk) and 'category' (varchar).
The 'details' table has a foreign key joining the categories table on 'cat_id'.

I'd like to have a dropdown list of the categories that when selected would filter the results of the details table.
To help explain... the SQL would be similar to "SELECT * FROM details WHERE cat_id = (the item selected from the dropdown)".

I saw the demo code for "Dependent Dropdowns" but I'm not understanding how to make just/only a dropdown in xCrud, if xCrud can in fact do this.

Otherwise I can create a dropdown list from mysql table data using php, but then the dropdown list would need to be enclosed in a FORM with either POST or GET, correct?

I'm lost, how to connect the xCrud datatable so that the dropdown can be used as a filter?

Thanks!
 

andyrav

New member
Joined
Mar 19, 2023
Messages
26
Reaction score
0
Points
1
Location
Uk
This is what i do
$db = \Xcrud_db::get_instance();
$sql = "SELECT col1 FROM table WHERE col1 like '%".$col1 ."%'";
$db->query($sql);
$data = $db->result();
$output = array();
foreach($data as $rows){
$output[$rows["col1 "]] = $rows["col1 "];
}
ksort($output);
$col1 = implode("','",$output);

$WZDjTpeJx->change_type('col1 ', 'select', null, $role);
 
Top Bottom