Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
single search not working
30/05/2010
01:15
Avatar
romaneduardo
Venezuela
Member
Members
Forum Posts: 3
Member Since:
26/03/2010
sp_UserOfflineSmall Offline

( apologize, and publish this post but do not see )

I do not understand why it does not work.
Image Enlarger
execute search
jbImage Enlarger
I hope, one row with result INV NO 654
ebImage Enlarger
but result same
Image Enlarger
my files:
grid.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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>Primera matriz</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/vader/jquery-ui-1.8.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-sp.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script type="text/javascript">
jQuery(document).ready(function(){
  jQuery("#list").jqGrid({
    url:'ejemplo.php?q=1',
    datatype: 'json',
    mtype: 'POST',
    colNames:['Inv No','Fecha', 'Monto','Impuesto','Total','Notas'],
    colModel :[
      {name:'invid', index:'invid', width:55},
      {name:'invdate', index:'invdate', width:90},
      {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}
    ],
    pager: '#pager', /* indica el elemento donde ir la barra de paginacin*/
    rowNum:10,
    rowList:[5,10,15,20,25,30],
    sortname: 'invid',
    sortorder: 'desc',
    viewrecords: true,
    caption: 'Mi primera matriz de datos con JqGrid'
  });
jQuery("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
});
</script>

 
</head>
<body>
<table id="list"></table>
<div id="pager"></div>
</body>
</html>

ejemplo.php
<?php
include("dbconfig.php");
// coment the above lines if php 5
//include("JSON.php");
//$json = new Services_JSON();
// end comment
$examp = $_REQUEST["q"]; //query number

$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;

$wh = "";
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
    $sarr = Strip($_REQUEST);
    foreach( $sarr as $k=>$v) {
        switch ($k) {
            case 'invid':
            case 'invdate':
            case 'note':
                $wh .= " AND ".$k." LIKE '".$v."%'";
                break;
            case 'amount':
            case 'tax':
            case 'total':
                $wh .= " AND ".$k." = ".$v;
                break;
        }
    }
}
//echo $wh;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($dbs) or die("Error conecting to db.");

switch ($examp) {
    case 1:
        $result = mysql_query("SELECT COUNT(*) AS count FROM invheader".$wh);
        $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)
        if ($start<0) $start = 0;
        $SQL = "SELECT invid, invdate, amount, tax,total, note FROM invheader".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
        $result = mysql_query( $SQL ) or die("Could not execute query.".mysql_error());
        $responce->page = $page;
        $responce->total = $total_pages;
        $responce->records = $count;
        $i=0;
        while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
            $responce->rows[$i]['invid']=$row['invid'];
            $responce->rows[$i]['cell']=array($row['invid'],$row['invdate'],$row['amount'],$row['tax'],$row['total'],$row['note']);
            $i++;
        }
        //echo $json->encode($responce); // coment if php 5
        echo json_encode($responce);
           
        break;
    case 3:
}
mysql_close($db);

function Strip($value)
{
    if(get_magic_quotes_gpc() != 0)
      {
        if(is_array($value))  
            if ( array_is_associative($value) )
            {
                foreach( $value as $k=>$v)
                    $tmp_val[$k] = stripslashes($v);
                $value = $tmp_val;
            }                
            else  
                for($j = 0; $j < sizeof($value); $j++)
                    $value[$j] = stripslashes($value[$j]);
        else
            $value = stripslashes($value);
    }
    return $value;
}
function array_is_associative ($array)
{
    if ( is_array($array) && ! empty($array) )
    {
        for ( $iterator = count($array) - 1; $iterator; $iterator-- )
        {
            if ( ! array_key_exists($iterator, $array) ) { return true; }
        }
        return ! array_key_exists(0, $array);
    }
    return false;
}
?>

Help, please.
30/05/2010
01:58
Avatar
tim
Calgary Alberta Canada
Member
Members
Forum Posts: 61
Member Since:
04/11/2009
sp_UserOfflineSmall Offline

This is a PHP to SQL issue, not a jqGrid issue.

From what I can see, not understanding anything about PHP, your

case 'invid':

is not being applied to the varialbe $wh

To troubleshoot this put your debugger on and look at the output for $wh inside your

switch ($examp) {
    case 1:

statement.

or just look at the actual SQL being sent to the database.

tim

05/06/2010
02:32
Avatar
romaneduardo
Venezuela
Member
Members
Forum Posts: 3
Member Since:
26/03/2010
sp_UserOfflineSmall Offline

Hi Tim.

Thanks for your response.

It was certainly a problem in PHP to SQL.

I mistakenly thought Jqgrid did everything. And of course, PHP and MYSQL code must be written by each user. Mainly MYSQL code for search functions.

The search module works for me as it is, but it was a difficult task to achieve.

For anyone who has the same doubt, the lesson learned is that: the code to execute searches with Jqgrid must be written yourself. The demos are just that, demos!

Thanks again Tim.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
22 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information