0

Hello, I am developing a website but I am stuck at a point.

I have a table having Sundays, video, and photo1, photo2, photo3 as columns.

I have a form on a web page having three check boxes "with videos", "with photos" and "Open on Sundays", I want to get results based on these controls please help me. If open on Sundays is checked then the query will return the results where Sundays have value "yes", if "with photo" is checked the query will return where photo1 or photo2 or photo3 is not empty.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Fest3er
0

Hello, I am developing a website but I am stuck at a point.

I have a table having Sundays, video, and photo1, photo2, photo3 as columns.

I have a form on a web page having three check boxes "with videos", "with photos" and "Open on Sundays", I want to get results based on these controls please help me. If open on Sundays is checked then the query will return the results where Sundays have value "yes", if "with photo" is checked the query will return where photo1 or photo2 or photo3 is not empty.

Here's a bit of code that might do the trick, assuming the checkboxes are ANDed together: if they check all three, then they will see records that show open on Sunday, have video and have at least one photo.

$where_and = " WHERE";
  $query = "
  SELECT * FROM my_table";
  if (sunday_is_checked)
  {
    $query .= "$where_and sunday = 'YES'";
    $where_and = " AND";
  }
  if (video_is_checked)
  {
    $query .= "$where_and video = 'YES'";
    $where_and = " AND";
  }
  if (photo_is_checked)
  {
    $query .= "$where_and (photo1 != ''";
    $query .= " OR photo2 != ''";
    $query .= " OR photo3 != '')";
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.