1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

function help?

Discussion in 'PHP' started by stompergames, Aug 9, 2008.

  1. #1
    I am using php include to include this function and it is giving me a:

    Parse error: syntax error, unexpected T_FUNCTION in /home1/stomperg/public_html/nintendogamesonline/functions.php on line 3

    error.

    Here is the code of the functions.php file:

    <? php

    function showHannsgMonitor($monitor)
    {
    echo(
    <div class="section">
    <div class="images">
    <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
    <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
    </div>
    <div class="description">
    <a href="#"></a>
    <ul>
    <li><strong>Color:</strong> <?php $hannsg['$monitor'][0] ?></li>
    <li><strong>Size:</strong> <?php $hannsg['$monitor'][1] ?></li>
    <li><strong>Resolution:</strong> <?php echo $hannsg['$monitor'][2] ?></li>
    <li><strong>Response Time:</strong> <?php echo $hannsg['$monitor'][3]

    ?></li>
    <li><strong>Input:</strong> <?php echo $hannsg['$monitor'][4] ?></li>
    <li><strong>Brightness:</strong> <?php echo $hannsg['$monitor'][5] ?></li>
    <li><strong>Contrast Ratio:</strong> <?php echo $hannsg['$monitor'][6]

    ?></li>
    <li><strong>Viewing Angle:</strong> <?php echo $hannsg['$monitor'][7]

    ?></li>
    <li><strong>Pixel Pitch:</strong> <?php echo $hannsg['$monitor'][8]

    ?></li>
    </ul>
    </div>
    <div class="revieworbuy">
    </div>
    <div class="clear"></div>
    </div>);
    }

    ?>




    Thanks for anyones help!!
     
    stompergames, Aug 9, 2008 IP
  2. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #2
    I don't believe echo has parentheses... () You should use quotes. That may make it think it's an unknown function.
     
    nfd2005, Aug 9, 2008 IP
  3. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Also, it seems that you are closing the PHP syntax ?> halfway through the echo...
     
    nfd2005, Aug 9, 2008 IP
    stompergames likes this.
  4. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    can I have echos in echos? I have a multidimensional array and I am calling the array parts which is why I have those "<? php echo $hannsg['$monitor'][8] ?>" blocks in there. Is that my problem?
     
    stompergames, Aug 9, 2008 IP
  5. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I am including a functions.php file in my index.html with one function that uses a multidimensional array data that is included as well, but I am getting an error that halts the loading of the page.

    Here is the error:
    Parse error: syntax error, unexpected T_FUNCTION in /home1/stomperg/public_html/nintendogamesonline/functions.php on line 3

    And here is the code to create the function that I am including:

    <? php

    function showMonitor($monitor)
    {
    echo(
    <div class="section">
    <div class="images">
    <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
    <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
    </div>
    <div class="description">
    <a href="#"></a>
    <ul>
    <li><strong>Color:</strong> $hannsg['$monitor'][0]</li>
    <li><strong>Size:</strong> $hannsg['$monitor'][1]</li>
    <li><strong>Resolution:</strong> $hannsg['$monitor'][2]</li>
    <li><strong>Response Time:</strong> $hannsg['$monitor'][3]</li>
    <li><strong>Input:</strong> $hannsg['$monitor'][4]</li>
    <li><strong>Brightness:</strong> $hannsg['$monitor'][5]</li>
    <li><strong>Contrast Ratio:</strong> $hannsg['$monitor'][6]</li>
    <li><strong>Viewing Angle:</strong> $hannsg['$monitor'][7]</li>
    <li><strong>Pixel Pitch:</strong> $hannsg['$monitor'][8]</li>
    </ul>
    </div>
    <div class="revieworbuy">
    </div>
    <div class="clear"></div>
    </div>);
    }

    ?>


    ^^^ Here is what the original post should have said if that helps any. Thanks!
     
    stompergames, Aug 9, 2008 IP
  6. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #6
    function showHannsgMonitor($monitor)
       {
          echo  '<div class="section">
                <div class="images">
                <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
                <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
                </div>
                <div class="description">
                <a href="#"></a>
                <ul>
                <li><strong>Color:</strong>'.$hannsg['$monitor'][0].'</li>
                <li><strong>Size:</strong>'.$hannsg['$monitor'][1].'</li>
                <li><strong>Resolution:</strong>'.$hannsg['$monitor'][2].'</li>
                <li><strong>Response Time:</strong>'.$hannsg['$monitor'][3].'</li>
                <li><strong>Input:</strong> '.$hannsg['$monitor'][4].'</li>
                <li><strong>Brightness:</strong>'.$hannsg['$monitor'][5].'</li>
                <li><strong>Contrast Ratio:</strong>'.$hannsg['$monitor'][6].'</li>
                <li><strong>Viewing Angle:</strong> '. $hannsg['$monitor'][7].'</li>
                <li><strong>Pixel Pitch:</strong>'.$hannsg['$monitor'][8].'</li>
                </ul>
                </div>
                <div class="revieworbuy">
                </div>
                <div class="clear"></div>
                </div>';
       }
    PHP:
     
    php-lover, Aug 9, 2008 IP
    stompergames likes this.
  7. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    that works, but my inserted parameter is not replacing the variable.

    EXAMPLE:
    when I call
    <?php showHannsgMonitor("JW155DBB") ?>

    it doesnt replace $monitor with JW155DBB everywhere I told it to.

    ------------------------
    what i what to happen is when the function is called, i want the parameter to replace all the variables in the code and then i want the function to print the raw code onto the html document exactly where it is called. maybe this helps some more?
     
    stompergames, Aug 9, 2008 IP
  8. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #8
    function showHannsgMonitor($monitor)
       {
          global $hannsg;      //<--you have to set your global variable inside your function
          
          echo  '<div class="section">
                <div class="images">
                <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
                <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
                </div>
                <div class="description">
                <a href="#"></a>
                <ul>
                <li><strong>Color:</strong>'.$hannsg[$monitor][0].'</li>
                <li><strong>Size:</strong>'.$hannsg[$monitor][1].'</li>
                <li><strong>Resolution:</strong>'.$hannsg[$monitor][2].'</li>
                <li><strong>Response Time:</strong>'.$hannsg[$monitor][3]
                
                .'</li>
                <li><strong>Input:</strong> '.$hannsg[$monitor][4].'</li>
                <li><strong>Brightness:</strong>'.$hannsg[$monitor][5].'</li>
                <li><strong>Contrast Ratio:</strong>'.$hannsg[$monitor][6]
                
                .'</li>
                <li><strong>Viewing Angle:</strong> '. $hannsg[$monitor][7]
                
                .'</li>
                <li><strong>Pixel Pitch:</strong>'.$hannsg[$monitor][8]
                
                .'</li>
                </ul>
                </div>
                <div class="revieworbuy">
                </div>
                <div class="clear"></div>
                </div>';
       }
    PHP:
     
    php-lover, Aug 9, 2008 IP
  9. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    but if i want to replace all the '$monitor' variables and NONE of the '$hannsg' ones then do i change the global to $monitor or leave it as is?


    php_lover, you are a great help rep+
     
    stompergames, Aug 9, 2008 IP
  10. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #10
    leave it like that. You pass in the monitor variable in your function argument.
     
    php-lover, Aug 9, 2008 IP
  11. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    you are the man! two reps+ for all posts!

    thanks a ton!!
     
    stompergames, Aug 9, 2008 IP
  12. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #12
    glad it's work..:)
     
    php-lover, Aug 9, 2008 IP