1. #1
    Sencha User
    Join Date
    Feb 2008
    Posts
    36
    Vote Rating
    0
    yozefff is on a distinguished road

      0  

    Default Simple livesearch with grid and JSON + PHP

    Simple livesearch with grid and JSON + PHP


    Well, finally got my livesearch with a datagrid+JSON+PHP working. I've even wrote a tutorial for it:

    http://extjs.com/learn/Tutorial:Buil...orm--chapter-1

    And the working example:

    http://www.leihitu.nl/ext-2.0.1/exam...utorial_final/

    greets

  2. #2
    Sencha - Training Team RWaters's Avatar
    Join Date
    Mar 2007
    Location
    Los Angeles, CA
    Posts
    714
    Vote Rating
    0
    RWaters is on a distinguished road

      0  

    Default


    Thanks for the contribution. Looks good. One suggestion would be to toss the code through something that would convert the tabs to spaces so that theres not an 8 space indent. I think most people find 2 or 4 easiest to read.

  3. #3
    Sencha User
    Join Date
    Feb 2008
    Posts
    36
    Vote Rating
    0
    yozefff is on a distinguished road

      0  

    Default


    ok .. thnx ... will do next time ;-)

  4. #4
    franckxx
    Guest

    Default rellay by thx !

    rellay by thx !


    Hi yazeff !

    I just want to say you ----> BIG THX

    i like your apps, i think use it....

    I've just one question :
    how can i show all entries (when page load), and filter with search entry ?

    bye and thx yto share ;-)

  5. #5
    Sencha User
    Join Date
    Feb 2008
    Posts
    36
    Vote Rating
    0
    yozefff is on a distinguished road

      0  

    Default


    thnx ....

    hmm yah it's possible. You'll need to modify the php script and the js file.

    replace the createDS function with this:

    Code:
    	// ----------------
    	//	Create datasource
    	// ----------------
    	function createDS()
    	{
    		ds = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: 'search.php',
                    method: 'POST'
                }),                        
                
                reader:  new Ext.data.JsonReader({
    				totalProperty: 'total',
    				root: 'results',
    				id: 'id',
    				fields: ['id','name','email','comments']
    			})					    
    			
    		});
    
    		ds.load(
    		{
    			params: 
    			{	
    				query:"dummy",
    				show:"all"
    			}
    		});				
    	}
    and the search.php :

    Code:
    <?php
    	//dl("json.so");
    	include("../connection.php");
    	include("../JSON.php");
    	
    	
    	function search($query="",$showAll=false)
    	{
    		$payload=array();
    		$payload["total"]=0;
    		$payload["results"]=array();
    		
    		$sql="";
    		if(trim($query)!="")
    		{
    			$sql="SELECT * FROM people WHERE (name LIKE '%" . mysql_real_escape_string(trim($query)) . "%')";
    			
    			if($showAll) $sql="SELECT * FROM people";
    			
    			if($rs=mysql_query($sql))
    			{
    				$payload["total"]=mysql_num_rows($rs);
    				while($data=mysql_fetch_assoc($rs))
    				{
    					$payload["results"][]=$data;
    				}
    			}
    		}
    		
    		$json = new Services_JSON();
    		return $json->encode($payload);		
    	}
    	
    	
    	
    	$searchResults=search();
    	if(connectDB("YOUR DATABASE NAME HERE"))
    	{
    		$showAll=false;
    		if(isSet($_POST["show"]) && $_POST["show"]=="all"))
    		{
    			$showAll=true;
    		}			
    		
    		if(isSet($_POST["query"]))
    		{
    			$searchResults=search($_POST["query"],$showAll);			
    		}
    	}
    	
    	print $searchResults;
    ?>
    should work ;-)

  6. #6
    Sencha User garraS's Avatar
    Join Date
    Oct 2007
    Location
    Argentina
    Posts
    203
    Vote Rating
    0
    garraS is on a distinguished road

      0  

    Default


    Thanks, nice tool ^^

  7. #7
    franckxx
    Guest

    Default


    Quote Originally Posted by yozefff View Post
    thnx ....

    hmm yah it's possible. You'll need to modify the php script and the js file.

    replace the createDS function with this:

    Code:
    	// ----------------
    	//	Create datasource
    	// ----------------
    	function createDS()
    	{
    		ds = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({
                    url: 'search.php',
                    method: 'POST'
                }),                        
                
                reader:  new Ext.data.JsonReader({
    				totalProperty: 'total',
    				root: 'results',
    				id: 'id',
    				fields: ['id','name','email','comments']
    			})					    
    			
    		});
    
    		ds.load(
    		{
    			params: 
    			{	
    				query:"dummy",
    				show:"all"
    			}
    		});				
    	}
    and the search.php :

    Code:
    <?php
    	//dl("json.so");
    	include("../connection.php");
    	include("../JSON.php");
    	
    	
    	function search($query="",$showAll=false)
    	{
    		$payload=array();
    		$payload["total"]=0;
    		$payload["results"]=array();
    		
    		$sql="";
    		if(trim($query)!="")
    		{
    			$sql="SELECT * FROM people WHERE (name LIKE '%" . mysql_real_escape_string(trim($query)) . "%')";
    			
    			if($showAll) $sql="SELECT * FROM people";
    			
    			if($rs=mysql_query($sql))
    			{
    				$payload["total"]=mysql_num_rows($rs);
    				while($data=mysql_fetch_assoc($rs))
    				{
    					$payload["results"][]=$data;
    				}
    			}
    		}
    		
    		$json = new Services_JSON();
    		return $json->encode($payload);		
    	}
    	
    	
    	
    	$searchResults=search();
    	if(connectDB("YOUR DATABASE NAME HERE"))
    	{
    		$showAll=false;
    		if(isSet($_POST["show"]) && $_POST["show"]=="all"))
    		{
    			$showAll=true;
    		}			
    		
    		if(isSet($_POST["query"]))
    		{
    			$searchResults=search($_POST["query"],$showAll);			
    		}
    	}
    	
    	print $searchResults;
    ?>
    should work ;-)
    Hi Yozefff,

    THX a lot for your help ;-)
    I've try the modification code, but it don't work for me... I think the problem is in the "search.php".
    when i load page, i don't see all result... (but no firebug error)

  8. #8
    Sencha User
    Join Date
    Feb 2008
    Posts
    36
    Vote Rating
    0
    yozefff is on a distinguished road

      0  

    Default


    hmm ok .. i didn't test it ;-)

    i'll test it now hahaha.

    Ok found it

    this line

    Code:
    if(isSet($_POST["show"]) && $_POST["show"]=="all"))
    should be

    Code:
    if(isSet($_POST["show"]) && $_POST["show"]=="all")
    live example:
    http://www.leihitu.nl/ext-2.0.1/exam...rial_final_v2/

  9. #9
    franckxx
    Guest

    Default


    You simply the Best !! like Tina turner !

    thx for this great modif

  10. #10
    Ext User
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    9
    Vote Rating
    0
    freese is on a distinguished road

      0  

    Default


    Would it be possible to make an editable Grid out of this cool tool? That would make it really an extremely good solution for data managing. Sorry if it is a stupid question, but I just started with ext. Thank you!

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar