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_TopicIcon
Ask: Integrated Search Toolbar->PHP-Mysql syntax
14/01/2010
14:37
Avatar
Candra
Guest
Guests

Dear all,

I want to use integrated earch toolbar on my jggrid. I want to modificate your PHP-MYSQL code but i do not understand about this especially with the bold:

$wh = "";
$searchOn = Strip($_REQUEST['_search']);
if($searchOn=='true') {
$sarr = Strip($_REQUEST);
foreach( $sarr as $k=>$v) {
switch ($k) {
case 'id':
case 'invdate':
case 'name':
case 'note':
$wh .= " AND ".$k." LIKE '".$v."%'";
break;
case 'amount':
case 'tax':
case 'total':
$wh .= " AND ".$k." = ".$v;
break;
}
}
}

Could you help me to explain the logic of this syntax, please????

Thank for your help

Regards,

Candra

14/01/2010
20:35
Avatar
newperson
Member
Members
Forum Posts: 27
Member Since:
28/12/2009
sp_UserOfflineSmall Offline

$searchOn = Strip($_REQUEST['_search']);

there is a function called Strip that will remove slashes from the user typed text

foreach( $sarr as $k=>$v) {

more or less this is pretty much saying for every value that the user entered in *note that the $v is data that comes out of your Strip function which as I mentioned it removes slashes from the user typed fields.

$wh .= ” AND “.$k.” LIKE '”.$v.”%'”;

If you noticed, your MYSQL syntax has .$wh at the end of it….and it needs this for searching basically this constructs a where clause that gives appends AND id, invdate,name,note plus a LIKE statement and since id,invdate,name,note are integer,text fields you are able to use the LIKE operator as opposed to float values such as amount, tax,total that is why you don't see the LIKE operator in $wh .= ” AND “.$k.” = “.$v;

Hope this helps understand it a little better.

PS when I first picked up jqgrids I had no clue about php/js/html, I still don't know a whole lot about them but I can find my way much easier now and have come up with some really nice functioning grids. It took me a while to get going with it and understand some of these basic concepts, If it weren't for the demos I wouldn't have been able to figure it out. My suggestion to you is to spend some time on the demo section and also IRC helps a lot, there are MYSQL/PHP/JavaScript channels you can join to ask specific questions which will point you in the right direction, I suggest using the freenode irc servers.

16/01/2010
07:57
Avatar
Candra
Guest
Guests

To newperson,

Thx for your explanation. But I still have problem on it.

<!-- /* Font Definitions */ @font-face {font-family:Calibri; mso-font-alt:"Century Gothic"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin-top:0cm; margin-right:0cm; margin-bottom:10.0pt; margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:Calibri; mso-fareast-font-family:Calibri; mso-bidi-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

I can not find the strip function on php manual but I find stripslashes, is it similar?because if i use Strip function it causes error.

<!-- /* Font Definitions */ @font-face {font-family:Calibri; mso-font-alt:"Century Gothic"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin-top:0cm; margin-right:0cm; margin-bottom:10.0pt; margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:Calibri; mso-fareast-font-family:Calibri; mso-bidi-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

if i run PHP-MYSQL example code with IE, the code do not work,could you help me find where is my error lies?

<!-- /* Font Definitions */ @font-face {font-family:Calibri; mso-font-alt:"Century Gothic"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin-top:0cm; margin-right:0cm; margin-bottom:10.0pt; margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:Calibri; mso-fareast-font-family:Calibri; mso-bidi-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

<?php

include 'config/connect.php';

 $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 = stripslashes($_REQUEST['_search']);

if($searchOn=='true') { $sarr = Strip($_REQUEST);

foreach( $sarr as $k=>$v) {

            switch ($k) {

                        case 'id':

                        case 'name':

                        case 'address':

                        case 'phone':

                        case 'fax':

                        case 'email':

                        $wh .= " AND ".$k." LIKE '".$v."%'";

            break;

                        case 'total':

                        $wh .= " AND ".$k." = ".$v;

            break; } }

            }

//echo $wh;

switch ($examp) { case 1: $result = mysqli_query($link, "SELECT COUNT(*) AS count FROM table WHERE ".$wh);

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);

$count = $row['count'];

 

            // calculate the total pages for the query

            if( $count >0 ) {

              $total_pages = ceil($count/$limit);

            } else {

              $total_pages = 0;

            }

 

            // if for some reasons the requested page is greater than the total

            // set the requested page to total page

            if ($page > $total_pages) $page=$total_pages;

 

            // calculate the starting position of the rows

            $start = $limit*$page - $limit;

 

            // if for some reasons start position is negative set it to 0

            // typical case is that the user type 0 for the requested page

            if($start < 0) $start = 0;

 

            // the actual query for the grid data

            $SQL = "SELECT * FROM table WHERE".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;

            $result = mysqli_query($link, $SQL ) or die("Couldn't execute query.".mysqli_error($link));

 

            $responce->page = $page;

            $responce->total = $total_pages;

            $responce->records = $count;

            $i=0;

            while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {

                        $responce->rows[$i]['id']=$row[id];

                        $responce->rows[$i]['cell']=array($row[id],$row[name],$row[address], $row[phone],$row[fax],$row[email],$row[total]);

 

                        $i++;

            } echo json->encode($responce);// coment if php 5 //echo

json_encode($responce); break; case 3:

}

mysqli_close($db);

 

?>

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
57 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