EasyUI
Home
Demo
Tutorial
Documentation
Download
Extension
Contact
Forum
EasyUI Forum
May 21, 2024, 03:28:30 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
:
Home
Help
Search
Login
Register
EasyUI Forum
>
General Category
>
EasyUI for jQuery
>
Search Function
Pages: [
1
]
« previous
next »
Print
Author
Topic: Search Function (Read 11992 times)
nvts
Newbie
Posts: 8
Search Function
«
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);
?>
Logged
stworthy
Administrator
Hero Member
Posts: 3581
Re: Search Function
«
Reply #1 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
Logged
nvts
Newbie
Posts: 8
Re: Search Function
«
Reply #2 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
Logged
stworthy
Administrator
Hero Member
Posts: 3581
Re: Search Function
«
Reply #3 on:
July 09, 2013, 04:34:45 PM »
It seems that your code has no problem.
Logged
nvts
Newbie
Posts: 8
Re: Search Function
«
Reply #4 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
«
Last Edit: July 10, 2013, 08:15:16 AM by nvts
»
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> News
=> General Discussion
=> EasyUI for jQuery
=> EasyUI for Angular
=> EasyUI for Vue
=> EasyUI for React
=> Bug Report
Loading...