I have some SQL functions, an HTML/JS form and a PHP script (which calls SQL functions with form parameters). The form just sends two parameters :
- date
- language
If date is empty, no problem, I can get the date of the day by PHP and pass it to my SQL request. But when $language is empty, I want to display results for all languages..
The php part :
$date = isset($_GET['date']) ? $_GET['date'] : '';
if (empty($date)) {
$date = date("Y-m-d");
}
$language = isset($_GET['language']) ? $_GET['language'] : '';
if (empty($language)) {
//$language =
}
$events = retrieve_events_by_type ($DB, $query, $language, $date);
My SQL function :
function retrieve_events_by_type ($DB, $type, $language, $date) {
$req = $DB->prepare("SELECT organizer, eventname, eventplace, language, eventdate, eventhour, eventminutes FROM events where eventtype = ? AND language = ? AND eventdate = ?");
$req -> bindParam(1, $type, PDO::PARAM_STR);
$req -> bindParam(2, $language, PDO::PARAM_STR);
$req -> bindParam(3, $date, PDO::PARAM_STR);
$req -> execute();
$events = $req->fetchAll(PDO::FETCH_ASSOC);
$req->closeCursor();
return ($events);
}
Can I get all languages with this SQL function ? Or am I forced to create other functions for all cases ..?
Thanks.
Aucun commentaire:
Enregistrer un commentaire