Title: Search Function Post by: nvts on July 09, 2013, 08:54:33 AM Hello,
I will try hopefully a simpler question. I have a simple search for data grid. I just can seem to pass the tbsearch input to the php file using the datagrid routine. Can any of you see what I did wrong. Thanks I know the value for tbsearch from my <input id> is being passed to my js search routine as i can store it to a var and then use an alert to display the result as you can see in the comment out code. function doSearch(){ var tbsname = tbsearch.value; $('#dg').datagrid('load',{ tbname : $('#tbsearch').val() }); //alert(tbsearch.value); //alert(tbsname); } I have this in the php file on my server. If i assign $findnames to a static string it works and only displays for that string if it is in either the first or last name. <?php $page = isset($_POST['page']) ? intval($_POST['page']) : 1; $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10; $findnames = isset($_POST['tbname']) ? mysql_real_escape_string($_POST['tbname']) : ''; $offset = ($page-1)*$rows; $result = array(); include 'conn.php'; $where = "lastname like '$findnames%' or firstname like '$findnames%' "; $rs = mysql_query("select count(*) from users where " . $where); $row = mysql_fetch_row($rs); $result["total"] = $row[0]; $rs = mysql_query("select * from users where " . $where . " limit $offset,$rows"); $items = array(); while($row = mysql_fetch_object($rs)){ array_push($items, $row); } $result["rows"] = $items; echo json_encode($result); ?> Title: Re: Search Function Post by: stworthy on July 09, 2013, 09:31:23 AM Here is the searching example that can retrieve the searching value and pass it to server.
http://www.jeasyui.com/tutorial/datagrid/datagrid24.php Title: Re: Search Function Post by: nvts on July 09, 2013, 03:40:29 PM Yes, I know. That is what I started with.
What is the difference to mine is what I am asking. It is in this line in the php $findnames = isset($_POST['tbname']) ? mysql_real_escape_string($_POST['tbname']) : ''; or in the search function with the datagrid function doSearch(){ $('#dg').datagrid('load',{ tbname : $('#tbsearch').val() }); } So what is wrong in the code. I compared it to the example, except I am just using one input. Howard Title: Re: Search Function Post by: stworthy on July 09, 2013, 04:34:45 PM It seems that your code has no problem.
Title: Re: Search Function Post by: nvts on July 10, 2013, 07:16:56 AM I just can't get it to pass the data to the php with the above line. The difference is that in the demo your are using the itemid and productid as the var names for all the way through to the php file on the server.
I changed my PHP to $findnames = $_REQUEST['tbname']; And this works just fine for the search and the java is the same. Do you seen any problem this way as datagrid is passing the var and POST is normally used for forms in PHP. Howard |