The query
Using the data posted by the form, we can now build a search query. (We only search for width, height and bytes if a value is given.)
// build query
$query = "SELECT * FROM images WHERE ";
// title
$query .= "img_title LIKE '%".$HTTP_POST_VARS["title"]."%' AND ";
// description
$query .= "img_descr LIKE '%".$HTTP_POST_VARS["descr"]."%' AND ";
// alt
$query .= "img_alt LIKE '%".$HTTP_POST_VARS["alt"]."%' AND ";
// width
if (trim($HTTP_POST_VARS["width"])!="") {
$query .= "img_width".$HTTP_POST_VARS["width_expr"].
$HTTP_POST_VARS["width"]." AND ";
}
// height
if (trim($HTTP_POST_VARS["height"])!="") {
$query .= "img_height".$HTTP_POST_VARS["height_expr"].
$HTTP_POST_VARS["height"]." AND ";
}
// bytes
if (trim($HTTP_POST_VARS["bytes"])!="") {
$query .= "img_bytes".$HTTP_POST_VARS["bytes_expr"].
$HTTP_POST_VARS["bytes"]." AND ";
}
// type
$query .= "img_alt LIKE '%".$HTTP_POST_VARS["type"]."%' AND ";
// finish the query (we ended every part with AND)
$query .= "1";