Closed Thread
Results 1 to 6 of 6

Thread: using echo and formatting code

  1. #1
    hayschooler is offline Learning Programmer
    Join Date
    Feb 2010
    Posts
    31
    Rep Power
    0

    using echo and formatting code

    If anyone can help, I'm using an include to reference variables I created for some images. I'm a little unsure how to get the syntax right. The program blows up with this code.

    This is my config.php file

    Code:
    <?php
    $logo 
    "images/logo.gif";
    $side_logo "images/side-logo.gif";
    $s_logo "images/s-logo.gif";
    ?>
    This is the code where I'm trying to include it:

    Code:
     public function 
          
    DisplayButton($width,$name,$url,$active true)
      {
      include 
    "config.php";
      
        echo 
    "if ($active) {
          echo "
    <td width "$width%\">
          <a href=\"$url\">
          <img src=\"$s-logo\" alt=\"$name"" border=\"0\" /></a>
          <a href=\"$url\"><span class=\"menu\">"
    $name"</span></a>
          </td>"
    ;
        } else {
          echo 
    "<td width=\"$width%\">
          <img src=\"$side-logo\">
          <span class=\"menu\">"
    $name"</span>
          </td>"
    ;
        }  
      } 
    If someone could show me how to properly do this I would appreciate it.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jaan Guest

    Re: using echo and formatting code

    Code:
    public function DisplayButton($width$name$url$active true) {
        
        if(
    $active == true) {
            
            echo 
    "<td width='".$width."%'>"
                
    ."<a href='".$url."'><img src='".$s_logo."' alt='".$name."' border='0' /></a>"
                
    ."<a href='".$url."'><span class='menu'>".$name."</span></a>"
                
    ."</td>";
                        
        }else {
            
            echo 
    "<td width='".$width."%'>"
                
    ."<img src='".$side_logo."' /><span class='menu'>".$name."</span>"
                
    ."</td>";
            
        }
        

    Maybe something like that ?

  4. #3
    hayschooler is offline Learning Programmer
    Join Date
    Feb 2010
    Posts
    31
    Rep Power
    0

    Re: using echo and formatting code

    Jaan,

    I tried your code but still no luck getting it to work. Thanks for trying. If you have any further suggestions I'm open. I'm lost with this stuff.
    My instructor said that the dots on either side of the variable wern't needed for concatenating. I don't understand it enough to know why?, but it works. This section is working for me though.
    Code:
    public function DisplayHeader()
      { 
       include 
    "config.php";
       
      echo 
    "<table width=\"100%\" cellpadding=\"12\" 
             cellspacing=\"0\" border=\"0\">
      <tr bgcolor =\"black\">
        <td align =\"left\"><img src = \"$logo\" /></td>
        <td>
            <h1>TLA Consulting Pty Ltd</h1>
        </td>
        <td align =\"right\"><img src = \"$logo\" /></td>
      </tr>
      </table>"
    ;
      } 
    I was confused with the additional styles in the section of code I asked about. Does this code make sense? I tried to apply this method to the code I asked about but I'm still confused. If you can see my errors please point them out?

  5. #4
    hayschooler is offline Learning Programmer
    Join Date
    Feb 2010
    Posts
    31
    Rep Power
    0

    Re: using echo and formatting code

    Some progress, I've got it now so the program doesn't blow up but the images still aren't coming through.
    This is what I have:

    Code:
    public function 
          
    DisplayButton($width,$name,$url,$active true)
      {
       include (
    "config.php");
     
        if (
    $active) {
          echo 
    "<td width = \"".$width."%\">
          <a href=\""
    .$url."\">
          <img src=\"$s-logo\" alt=\""
    .$name."\" border=\"0\" /></a>
          <a href=\""
    .$url."\"><span class=\"menu\">".$name."</span></a>
          </td>"
    ;
        } else {
          echo 
    "<td width=\"".$width."%\">
          <img src=\"$side-logo\">
          <span class=\"menu\">"
    .$name."</span>
          </td>"
    ;
        }  
      } 
    Can anyone see what is causing the problem?

  6. #5
    hayschooler is offline Learning Programmer
    Join Date
    Feb 2010
    Posts
    31
    Rep Power
    0

    Re: using echo and formatting code

    Ok it's resoloved, another dumb error, image names were s-logo, side-logo, the variable names were $s_logo and $side_logo. I mis-named variables $s-logo & $side-logo in the code. Thanks for taking a look at it.

  7. #6
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: using echo and formatting code

    your problem with the concatenations (.) is that you have used a string that covers many lines,
    and Jaan used one string per row and concatenated them instead, and he probably did that
    because of readability.

    Your version uses variable parsing within the strings, Jaan choose to not parse them inside the
    string, probably also by readability. Neither way is wrong, it's just two versions of the same thing
    what you choose is up to your personal style, or, if you are cooperating with others in larger projects,
    what the project you are working in has decided to use.
    to use as code style.
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. echo <a href>
    By newphpcoder in forum PHP Development
    Replies: 1
    Last Post: 05-12-2011, 02:23 PM
  2. add code for font size under php echo code
    By newphpcoder in forum PHP Development
    Replies: 2
    Last Post: 11-10-2010, 11:03 PM
  3. Formatting text (Short Code)
    By photoScan in forum C# Programming
    Replies: 0
    Last Post: 10-24-2010, 01:23 PM
  4. ECHO to DIV
    By ductiletoaster in forum PHP Development
    Replies: 3
    Last Post: 03-19-2010, 07:36 AM
  5. Looking for code to integrate for formatting abilities
    By highamperage in forum PHP Development
    Replies: 5
    Last Post: 02-27-2010, 12:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts