PHPing with ? "true" : "false" gives me a headacke

Discussion in 'PHP' started by Scorpiono, Aug 13, 2008.

  1. #1
    I'm not use with ? : etc coding with PHP, i barely know how it's called, I'd like to know as well, but most of all trying to find what's wrong in my code.

    Basically all i want is swap the css ID if the page is index.php or not

    I appreciate any help ;)

    echo '
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Manele &raquo; cauta si downloadeaza manele doar la manele.me</title>
    
    <link rel="stylesheet" href="/style.css" type="text/css" />
    
    </head>
    
    <body>
    
    	<div id="content">
    
            <h1 class="normal">manele.me &raquo; locul de unde poti downloada manele gratis</h1>
    
        	[COLOR=RED][B]<a href="#"><div id="'. ($GLOBALS['pagename']="index.php") ? 'header' : 'header-permalink' .'">Manele.me</div></a>[/B][/COLOR]
    
    		';
    Code (markup):
    I get the following error:

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/manele/public_html/header.php on line 27
    
    Parse error: syntax error, unexpected '"' in /home/manele/public_html/header.php on line 27
    Code (markup):
     
    Scorpiono, Aug 13, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    It's called ternary operator. And use commas to "split" the string, instead of the periods. Or wrap the whole ternary operation into parenthesis.
     
    nico_swd, Aug 13, 2008 IP
  3. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Worked, thank you kindly!
     
    Scorpiono, Aug 13, 2008 IP
  4. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Haha, I can't rep you as I have just repped you last time.. :)
     
    Scorpiono, Aug 13, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    On anther note... you have to use 2 equal signs for comparisons. One will assign the variable.
     
    nico_swd, Aug 13, 2008 IP
  6. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Indeed thank you.
     
    Scorpiono, Aug 13, 2008 IP