Answer the question
In order to leave comments, you need to log in
How to rewrite this in Django?
<?php
$pdo = new PDO('mysql:host=localhost;dbname=gb', 'root', '');
$select = 'SELECT *';
$from = 'FROM workers';
$where = 'WHERE TRUE';
$opts = isset($_POST['filterOpts'])? $_POST['filterOpts'] : array('');
if (in_array("hasCar", $opts)){
$where .= " AND hasCar = 1";
}
if (in_array("speaksForeignLanguage", $opts)){
$where .= " AND speaksForeignLanguage = 1";
}
if (in_array("canWorkNights", $opts)){
$where .= " AND canWorkNights = 1";
}
if (in_array("isStudent",
$opts)){ $where .= " AND isStudent = 1";
}
$sql = $select . $from. $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
?>
How to rewrite this in Django ?
How to replace $where = ' WHERE TRUE'; in django?
How to replace if (in_array("speaksForeignLanguage", $opts)) in Django ?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question