Can someone PLEASE tell me why this doesn't work? ive racked my brain till i dont have one anymore....
if i take out the where " . $where . " it works but the search function fails.
If i do a SELECT * from description where " . $where . " it works fine but the media_type is wrong.
PLEASE HELP!!

<?php
include 'conn.php';
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'ID';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'desc';
$ID = isset($_REQUEST['ID']) ? mysql_real_escape_string($_REQUEST['ID']) : '';
$TITLE = isset($_REQUEST['TITLE']) ? mysql_real_escape_string($_REQUEST['TITLE']) : '';
$DESCRIPTION = isset($_REQUEST['DESCRIPTION']) ? mysql_real_escape_string($_REQUEST['DESCRIPTION']) : '';
$VERSION = isset($_REQUEST['VERSION']) ? mysql_real_escape_string($_REQUEST['VERSION']) : '';
$filterRules = isset($_POST['filterRules']) ? ($_POST['filterRules']) : '';
$cond = '1=1';
if (!empty($filterRules)){
$filterRules = json_decode($filterRules);
print_r ($filterRules);
foreach($filterRules as $rule){
$rule = get_object_vars($rule);
$field = $rule['field'];
$op = $rule['op'];
$value = $rule['value'];
if (!empty($value)){
if ($op == 'contains'){
$cond .= " and ($field like '%$value%')";
} else if ($op == 'greater'){
$cond .= " and $field>$value";
}
}
}
}
$offset = ($page-1)*$rows;
$result = array();
$where = "ID like '%$ID%' OR TITLE like '%$TITLE%' or DESCRIPTION like '%$DESCRIPTION%' or VERSION like '%$VERSION%' ";
$rs = mysql_query("select count(*) from description where " . $where);
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("SELECT `description`.*,`media`.`media_type` FROM `description` RIGHT OUTER JOIN `media` ON (`media`.`media_type` = `description`.`MEDIA_TYPE`) WHERE " . $where . " order by $sort $order limit $offset,$rows ") ;
$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
//$checked = $result['REQUEST'];
echo json_encode($result);
?>