Forum
Topic RSS
02:51
19/10/2009
OfflineHello,
I've been struggling with the search button in the navbar for days.
I may be doing this completely wrong but it's not working and I really cannot figure out why.
If I add the jqGrid Demos to my local server and execute them, the search button brings up the search form and hands me the correct results. E.g. I search Id, equals, 2, and it shows me the row with id 2.
Now, I copy the code exactly, both HTML and PHP, into a seperate file and execute.
I press the search button, the form comes up and search for Id, equals, 2. Now, either nothing happens or the search function returns the entire table.
Is the search button meant to work just by adding it, or must I write additional code for it to work?
My HTML
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DT.....o;>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>My Third Grid</title>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”css/ui-lightness/jquery-ui-1.7.2.custom.css” />
<link rel=”stylesheet” type=”text/css” media=”screen” href=”css/ui.jqgrid.css” />
<style>
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src=”js/jquery-1.3.2.min.js” type=”text/javascript”></script>
<script src=”js/i18n/grid.locale-en.js” type=”text/javascript”></script>
<script src=”js/jquery.jqGrid.min.js” type=”text/javascript”></script>
</head>
<body>
<table id=”list”></table>
<div id=”pager”></div>
<input type=”BUTTON” id=”bsdata” value=”Search” /> <br />
<input type=”BUTTON” id=”bedata” value=”Edit Selected” />
</body>
</html><script type=”text/javascript”>
jQuery().ready(function (){
jQuery(”#list”).jqGrid({
url:'server.php?q=1',
datatype: “xml”,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:75},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager'),
sortname: 'id',
viewrecords: true,
sortorder: “asc”,
caption:”XML Example”,
editurl:”server.php”,
}).navGrid('#pager',{edit:false,add:false,del:false})
;});
jQuery(”#bsdata”).click(function(){
jQuery(”#list”).searchGrid(
{sopt:['cn','bw','eq','ne','lt','gt','ew'], closeOnEscape:true}
);
});
$(”#bedata”).click(function(){
var gr = jQuery(”#list”).getGridParam('selrow');
if( gr != null ) jQuery(”#list”).editGridRow(gr,{height:280,reloadAfterSubmit:false});
else alert(”Please Select Row”);
});</script>
My PHP
<?php
include(”dbconfig2.php”);
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row – i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die(”Connection Error: ” . mysql_error());mysql_select_db($database) or die(”Error conecting to db.”);
$result = mysql_query(”SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id”);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page – $limit; // do not put $limit*($page – 1)
$SQL = “SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE “
.” a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit”;
$result = mysql_query( $SQL ) or die(”Couldn?t execute query.”.mysql_error());if ( stristr($_SERVER["HTTP_ACCEPT"],”application/xhtml+xml”) ) {
header(”Content-type: application/xhtml+xml;charset=utf-8″); } else {
header(”Content-type: text/xml;charset=utf-8″);
}
$et = “>”;echo “<?xml version='1.0' encoding='utf-8'?$et\\n”;
echo “<rows>”;
echo “<page>”.$page.”</page>”;
echo “<total>”.$total_pages.”</total>”;
echo “<records>”.$count.”</records>”;
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo “<row id='”. $row[id].”'>”;
echo “<cell>”. $row[id].”</cell>”;
echo “<cell>”. $row[invdate].”</cell>”;
echo “<cell><![CDATA[". $row[name].”]]></cell>”;
echo “<cell>”. $row[amount].”</cell>”;
echo “<cell>”. $row[tax].”</cell>”;
echo “<cell>”. $row[total].”</cell>”;
echo “<cell><![CDATA[". $row[note].”]]></cell>”;
echo “</row>”;
}
echo “</rows>”;?>
dbconfig2.php contains the data needed to access local server, ofcourse.
Any help regarding this would be most appreciated
Regards,
Peter
06:28
19/10/2009
OfflineShould anyone want to see what I did, here's what I put in the “someurl.php”
someurl.php
<?php
// Get information from entry
$id = $_POST['id']; //id field from POST above
$date = $_POST['invdate']; //date field from POST above
$client = $_POST['client_id']; //client field from POST above
$amount = $_POST['amount']; //amount field from POST above
$tax = $_POST['tax']; //tax field from POST above
$total = $_POST['total']; //total field from POST above
$note = $_POST['note']; //note field from POST above// connect to the MySQL database server
include 'php/dbconfig2.php';
$con = mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
@mysql_select_db($database,$con) or die("Error connecting to db.");$add = "INSERT INTO invheader (id,invdate, client_id ,amount,tax,total,note) VALUES ('" . NULL . "','" . $date . "','" . $client . "',
'" . $amount . "','" . $tax . "','" . $total . "','" . $note . "')";$upd = "UPDATE invheader SET invdate = '" . $date . "', client_id = '" . $client . "',
amount = '" . $amount . "', tax = '" . $tax . "', total = '" . $total . "', note = '" . $note . "' WHERE id='" . $id . "'";$del = "DELETE FROM invheader WHERE id='" . $id . "'";
// ADDS NEW APP RECORD
if($_REQUEST[oper]=='add') {
if (mysql_query($add,$con))
{
echo "Inventory head added.";
}
else
{
echo "Error adding inventory header: " . mysql_error();
}// MODIFIES USER RECORD
} elseif($_REQUEST[oper]=='edit') {if (mysql_query($upd,$con))
{
echo "Inventory head edited.";
}
else
{
echo "Error editing inventory header: " . mysql_error();
}// DELETES USER RECORD AND ASSOCIATED ACCESS RELATIONSHIPS
} elseif($_POST[oper]=='del') {
if (mysql_query($del,$con))
{
echo "Inventory header deleted.";
}
else
{
echo "Error deleting inventory header: " . mysql_error();
}}
mysql_close($con);
?>
Most Users Ever Online: 994
Currently Online:
39 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66
Log In
Home