Same output, but not same at all..

Discussion in 'PHP' started by AmidalaX, Jan 30, 2011.

  1. #1
    Hi there, sry for bad topic name, I dont know how to better characterize it.

    So... Im using jQuery with JSON to parse my data. I think its php problem.

    I have two same outputs which are
    URL: ?callback=?a
    ?a([{"zn_id":2,"zn_meno":"Acer"},{"zn_id":"21","zn_meno":"Acerq"},{"zn_id":1,"zn_meno":"Asus"},{"zn_id":"11","zn_meno":"Asusq"}])
    Code (markup):
    Script 1: (working with json jquery)
    
    $input = strtolower(get_var('callback'));
    $len = strlen(substr($input, 1));
    
    foreach ($cache_znacky as $id => $znacka)
    {
    		$znacky[] = array('zn_id' => $id, 'zn_meno' => $znacka);
    		$znacky[] = array('zn_id' => $id.'1', 'zn_meno' => $znacka.'q');
    }
    PHP:
    Script 2: (not working with json jquery), but output is same :/
    
    $input = strtolower(get_var('callback'));
    		$len = strlen(substr($input, 1));
    foreach ($cache_znacky as $id => $znacka)
    {
    	if (strtolower(substr(utf8_decode($znacka),0,$len)) == substr($input, 1))
    	{
    		$znacky[] = array('zn_id' => $id, 'zn_meno' => $znacka);
    		$znacky[] = array('zn_id' => $id.'1', 'zn_meno' => $znacka.'q');
    	}
    }
    PHP:
    I need to use Script 2 to parse data which I want to get in json.

    Can anyone please help me to solve this? Thank you
     
    AmidalaX, Jan 30, 2011 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What do you mean by the second script is not working?

    Seems like the "if" condition is not met, try to figure out why.
     
    Greg Carnegie, Jan 31, 2011 IP
  3. AmidalaX

    AmidalaX Greenhorn

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    "if" is OK, as I told, result is SAME. When I use strlen or substr or mb_strlen, etc... json sop working, but result is still same.

    JSON connect is ok when it gets result from first script, but its not working getting result from secont script but echo of that scrips are exactly same.

    When I use select from mysql for get all results with no use of strlen or substr, its ok again...

    $sql = mysql_query('SELECT zn_meno FROM znacky');
    		//echo 'SELECT zn_meno FROM znacky WHERE zn_meno LIKE "' . substr(mb_convert_case($input, MB_CASE_LOWER, 'UTF-8'), 1) . '%"';
    		while ($row = mysql_fetch_object($sql))
    		{
    			$znack[] = array('znacka' => $row->zn_meno);
    		}
    		
    		//print_r($znack);
    		
    		$response = $input . "(" . json_encode($znack) . ")";  
        	echo $response;
    PHP:
    but when I use that commented sql its not working, but result is ok.

    Demo:
    Mysql select with no WHERE - http://www.pc-burza.eu/ajax/generate.php?mode=znacka2&callback=?a
    Mysql select with WHERE - http://www.pc-burza.eu/ajax/generate.php?mode=znacka&callback=?a

    Syntax is same, but first is working, second not.
     
    Last edited: Jan 31, 2011
    AmidalaX, Jan 31, 2011 IP