Hello,
I am creating a form which pulls information from my SQL database. Initially my form had two fields, ‘language’ and ‘prefecture’ . Thanks to daveismyname on this forum, I managed to get the form to work, so that when no values were returned the form processed correctly. My code to do this is below:
[php]<?php
$language = $_POST[‘language’];
$prefecture = $_POST[‘prefecture’];
$sql = “SELECT * FROM teacher_table WHERE language = '”.$language."’ AND prefecture = ‘".$prefecture."’ ";
$result =mysqli_query($db_connection, $sql);
if (count(mysqli_fetch_array($result)) > 0)
{
…displays output
else{
// No Results
redirect_to (‘no_results.php’);
db_disconnect($db_connection);
exit;
}
[/php]
However, I am now trying to add a checkbox to the form which has the function of basically 'only show values where photo field =1.
I tried to append my sql statement to
[php]$sql = “SELECT * FROM teacher_table WHERE language = '”.$language."’ AND prefecture = ‘".$prefecture."’ AND photo = '".$photo." ";[/php]
However, the problem with this is (I think?) if no results are returned from language and prefecture, a result is generally always returned from photo (either checked or unchecked -1 or 0) so if there are no results my code never gets to the else statement as
if (count(mysqli_fetch_array($result)) > 0)
will always return a result greater than 0. I think?
Also - and making things a bit more complicated - if the box is unchecked, I’d like the database to return values where photo is 0 and/or 1 (true and / or false). My form code is:
[php]
[/php]
Many thanks for reading. I hope that makes sense.