please help, php issue. should be if/else statements?

Discussion in 'PHP' started by monkeyclap, Apr 18, 2010.

  1. #1
    hello, hope you can help me out...

    i've got the following code to display a list of recent searches:

    function display_table(){
    	$content = file("list.txt");
    	$return = '<p>';
    	$lines = count($content);
    	for($i=0;$i<$lines;$i++){
    		
    		$return .= $content[$i];
    		if($i == $lines - 1){
    
    		}else{
    			$return .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    		}
    	}
    	$return .= "</p>";
    	return $return;
    }
    PHP:
    but you'll see on the 4th line down where the new line starts, it indents it with 5 spaces.

    how can i change the code so it does separate search terms with 5 spaces, but not include the 5 spaces in the beginning of a new line?

    [​IMG]

    as always, much appreciated!
     
    monkeyclap, Apr 18, 2010 IP
  2. aTo

    aTo Active Member

    Messages:
    473
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    #2
    function display_table()
    {
        $content = file("list.txt");
        $return = '<p>';
        $lines = count($content);
        $i = 0;
       while($i < $lines)
       {
       $return .= $contents[$i];
       if($i != $lines - 1)
              $return .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
       $i++;
       }
        $return .= "</p>";
        return $return;
    }
    PHP:
    try this mate... not so sure, just try this...
     
    aTo, Apr 18, 2010 IP
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    no that is no good at all... now nothing shows up... any more ideas? thanks btw
     
    monkeyclap, Apr 18, 2010 IP
  4. TYPELiFE

    TYPELiFE Peon

    Messages:
    109
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    function display_table(){
        $content = file("list.txt");
        $return = '<p>';
        $lines = count($content);
        for($i=0;$i<$lines;$i++){
            $return .= '<div style="display: inline; margin-right: 10px;">';
            $return .= $content[$i];
            if($i == $lines - 1){
    
            }else{
                $return .= "</div>";
            }
        }
        $return .= "</p>";
        return $return;
    }
    Code (markup):
    Something like that would probably work better. If not, let me know, I'll rewrite that function for you.
     
    TYPELiFE, Apr 21, 2010 IP
    monkeyclap likes this.
  5. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #5
    thanks for that! did a little tweaking myself and it works, cheers!
     
    monkeyclap, Apr 21, 2010 IP