This question already has an answer here:
I am working on an ajax script, and this php code is giving real tough time by always printing 0 results.
I doubted query so I directly ran it in phpmyadmin and got a row of results. so definitely nothing wrong with query.
Any help?
function processDrpdown($selectedVal) {
$sql = "SELECT id, name FROM mdl_question_categories where parent = $selectedVal";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "Name: " . $row["name"]. "<br>";
echo "ID: " . $row["id"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
// echo $selectedVal;
}
</div>