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.

Recommended Answers

All 3 Replies

Knowing which technology you use collect data from form and query database would be nice...
PHP/JSP/ASP????

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 != '')";
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.