[SOLVED] search engine with checkbox

flyboeing 12 Nov, 2011
Hello all,

I have made a basic search form that contains textboxes and drop down menus. Now I would like to have a checkbox. This checkbox can be checked if you only want to see the results that contains a URL of a photo. Not every row in my database has a URL of a photo, so when this box is checked, It has to see if the row contains an image.

How can this be done?
GreyHead 12 Nov, 2011
Hi Flyboeing,

Will WHERE `url` != '' do it?
flyboeing 12 Nov, 2011
Thank you for your fast reply.
But how can I put this in my where code?

This is my code:
<?php
$search_array = array('reg', 'aircraft', 'fotograaf', 'year', 'month', 'owner2', 'type', 'section');
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '%$value%' ";
  }
}
if ( !empty($where) ) {
  echo " WHERE ".explode(' AND ', $where);
}?>


In my form, I have to add a checkbox code?
GreyHead 13 Nov, 2011
Hi flyboeing,

Yes you'd need to add a checkbox.
<?php
$search_array = array('reg', 'aircraft', 'fotograaf', 'year', 'month', 'owner2', 'type', 'section');
$where = array();
foreach ( $search_array as $search ) {
  $value = JRequest::getVar($search, '' , 'post');
  if ( $value ) {
    $where[] = " $search LIKE '%$value%' ";
  }
}
$images = JRequest::getString('images_only', '', 'post');
if ( $images ) {
  $where[] = "`url` != '' ";
}
if ( !empty($where) ) {
  echo " WHERE ".explode(' AND ', $where);
}?>

Bob
flyboeing 13 Nov, 2011
Thank you very much Bob!

I just tried it, after some testing with it. I made some small mistake, but it is working now :wink:
This topic is locked and no more replies can be posted.