Jump to content

using echo and formatting code

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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

<?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:

 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
Guest_Jaan_*

Guest_Jaan_*
  • Guests
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 ?

#3
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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.
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?

#4
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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:

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?

#5
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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.

#6
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
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