EasyUI Forum
September 15, 2025, 03:27:10 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid search php mysql  (Read 8586 times)
tooletime
Newbie
*
Posts: 8


View Profile Email
« on: March 09, 2016, 03:44:49 PM »

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!!  Grin

Code:
<?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);
?>


« Last Edit: March 09, 2016, 04:06:31 PM by tooletime » Logged
nprioleau
Newbie
*
Posts: 12


View Profile
« Reply #1 on: March 10, 2016, 12:51:57 AM »

I battled for ages with this but have got it working with the code below, hope this helps?

<?
require('kernal.php');
$itemid = trim(strip_tags($_REQUEST['id']));

// Get sales
$getRows = $db->query(sprintf("SELECT *, p.prod_productID, p.prod_productName FROM sales_detail inner join products p on p.prod_productID = salesd_productID WHERE salesd_salesID = '$itemid' GROUP BY salesd_ID")) or SQLError();

while($row = $getRows->fetch_assoc()) {
    $rows[] = $row;
}
$smarty->assign('rowsNum', $total);
$smarty->assign('rows', $rows);
echo json_encode($rows);

?>
Logged
tooletime
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: March 10, 2016, 08:39:56 AM »

thank you for your reply and believe it or not i got it working after i posted this LOL..

This is how i got it to work.  something to do with if you are using double quotes, then your variables have to be in brackets... go figure...

Original:
$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 ") ;

NEW:
$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 ") ;
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!