A foreach question

Discussion in 'PHP' started by selen, Jun 10, 2010.

  1. #1
    Hello, I have a problem with a jquery function, but jquery I don't know very well and I made it work in Firefox but in IE it's not working. I change now my php code because the foreach function is not working in IE, that's my code:

    $search->setsearchname($_POST['queryString']);
    $results = $search->results ();
    $i = 0;
    foreach ($results as $res) {
             echo "<li> <a href='suggest.php?mid=".$res->imdbid()."'>".$res->title()." (".$res->year().")</li>";$i++;
        if ($i > 11) break;
    
    	}
    PHP:
    Now I want know if I can echo the results out of the foreach loop with all the values, then it should work in IE
     
    selen, Jun 10, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    If its not working in IE then its an html question not a foreach or php question.

    When you say it doesn't work in IE what do you actually mean?
    When you view the browser source does all the html look as it should?
     
    sarahk, Jun 10, 2010 IP
  3. selen

    selen Well-Known Member

    Messages:
    525
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    118
    #3
    Yes I know, but I don't know what's wrong, that's the whole code:

    require_once('config.php');
    require_once('include/functions.php');
    require_once('admin/imdb/imdbsearch.class.php');
    require_once('admin/imdb/imdb.class.php');
    $search = new imdbsearch();
    ob_end_clean();
    
    $output 	 = '';
    
    $queryString = trim($_POST['queryString']);
    
    // Is there a posted query string?
    if($queryString != '') 
    {
    	error_reporting(0);
    	$queryString = secure_sql($queryString); 
    
    	//	only perform queries if the length of the search string is greather than 3 characters
    	if(strlen($queryString) >= 3)
    	{
    		$num_res = 0;
    		if(strlen($queryString) > 3)
    		{
    			$sql	 = "SELECT uniq_id, year, video_title FROM pm_videos 
    						WHERE MATCH(video_title) 
    						AGAINST ('$queryString') AS score ORDER BY score ASC LIMIT 10";
    			$query	 = @mysql_query($sql);
    			$num_res = @mysql_num_rows($query);
    		}
    		if($num_res == 0)
    		{
    			$query = @mysql_query("SELECT year, video_title, uniq_id FROM pm_videos WHERE  video_title LIKE '%$queryString%' LIMIT 10");
    		}
    		
    		if($query)
    		{
    			while($result = mysql_fetch_array($query))
    			{
    				$output .= '<li onClick="fill(\''.$result['video_title'].' '.$result['year'].'\');">';
    				
    				if (_THUMB_FROM == 2)	//	Localhost
    				{
    					$output .= '<img src="'. show_thumb($result['uniq_id']) .'" width="32" align="absmiddle" style="margin: 1px 4px;" alt="'.$result['video_title'].' '.$result['year'].'" />';
    				}
    				$output .= '<a href="'. grabberlink($result['uniq_id'], $result['year'], $result['video_title']).'" title="'.$result['video_title'].' '.$result['year'].'">'.fewchars("".$result['video_title']." (".$result['year'].")", 35).'</a>';
    				$output .= '</li>';
    				
    			}
    		} 
    		else 
    		{
    			$output = $lang['search_results_msg3'];
    		}
    	}
    }
    echo $output;
    $search->setsearchname($_POST['queryString']);
    $results = $search->results ();
    
    $i = 0;
    
    foreach ($results as $res) {
    	
        echo "<li> <a href='suggest.php?mid=".$res->imdbid()."'>".$res->title()." (".$res->year().")</li>";
    	
        $i++;
        if ($i > 11) break;
    	}
    	
    exit();
    PHP:
    The problem is after echo $output it doesn't show this and it shows only the last one of the foreach, I don't use often IE I just wanted look how it looks like in IE then I saw it's not working at all
     
    Last edited: Jun 10, 2010
    selen, Jun 10, 2010 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #4
    I'd comment out this line for now
    error_reporting(0);
    PHP:
    and can you post what is sent to the browser (ie view source)?
     
    sarahk, Jun 10, 2010 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    Just a thought, your html form does it have all the appropriate name="something" & id="something" written into its <input types ?
     
    MyVodaFone, Jun 11, 2010 IP