Reload shortcode on dropdown box changed
-
Hi
I am writing a plugin which very simply loads data from a table in the database and displays it in a table on the frontend.
At the top of my table I have several dropdown boxes which are used to filter the data.
How do I go about reloading and updating the SQL query each time the dropdown boxes are changed?
I’m very new to developing in PHP so if any of my code is incorrect then please feel free to point it out to me.
Thanks
function renderswaplist() { $output = '<table> <tr> <td><select name="baseSearch" id="baseSearch"><option value="" selected="selected">All</option></select></td> <td><select name="roleSearch" id="roleSearch"><option value="" selected="selected">All</option></select></td> <td><select name="dateSearch" id="dateSearch"><option value="" selected="selected">Any</option></select></td> <td><select name="lengthSearch" id="lengthSearch"><option value="" selected="selected">Any</option></select></td> <td><select name="timeSearch" id="timeSearch"><option value="" selected="selected">Any</option></select></td> <td></td> <td></td> <td></td> </tr> <tr> <th>Base</th> <th>Role</th> <th>Date</th> <th>Days</th> <th>Check In</th> <th>Route</th> <th>Staff Number</th> <th>Comments</th> </tr>'; global $wpdb; $tablename = $wpdb->prefix . "swaplist"; foreach( $wpdb->get_results("SELECT * FROM $tablename;") as $key => $row) { $crewnumber = $row->crewnumber; $role = $row->role; $base = $row->base; $date = $row->startdate; $length = $row->length; $checkin = $row->checkin; $route = $row->route; $comments = $row->comments; $formatteddate = date( 'd M', strtotime($date)); $formattedcheckin = date( 'H:i', strtotime($checkin)); $output .= "<tr> <td>$base</td> <td>$role</td> <td>$formatteddate</td> <td>$length</td> <td>$formattedcheckin</td> <td>$route</td> <td>$crewnumber</td> <td>$comments</td> </tr>"; } $output .= '</table>'; return $output; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Reload shortcode on dropdown box changed’ is closed to new replies.