Page 1 of 1

Simple questions for a beginner

Posted: Wed Sep 05, 2007 3:58 pm
by Brik
OK - I'm not a programmer. I am trying to learn some things on my own.

My first question has to do with formatting PHP output.

Here is a snippet

Code: Select all

{                                    
echo "<tr>  <td>$TopLevel</td>       
	          <td>$category</td>       
	          <td>$offeringsname</td>  
	          <td>$resnames</td></tr>";
}
This code works fine. The variables are being pulled from a database, no problem.

Code: Select all

{                                     
echo "<tr>  <td><b>$TopLevel</b></td> 
	          <td>$category</td>        
	          <td>$offeringsname</td>   
	          <td>$resnames</td></tr>"; 
}
The above code also works fine, showing the contents of the row as bold. So far so good.

Code: Select all

{                                                
echo "<tr>  <td bgcolor="#00CCFF">$TopLevel</td> 
	          <td>$category</td>                   
	          <td>$offeringsname</td>              
	          <td>$resnames</td></tr>";            
}
I would expect this code to color the background of the column, it doesn't.
My error is
Parse error: syntax error, unexpected '>' in C:\www\output_all2.php on line 51
So, what am I doing wrong? AND more importantly, anyone had a good reference to documentation that explains formatting table output?

My next question has to do with using variables to define formatting, in other words I want my background color to change (red, blue) depending on a value (1,0) in a database.

Go easy on me please.

Thanks!

Posted: Wed Sep 05, 2007 5:21 pm
by Defkon1
you have to escape the double quotes:

Code: Select all

echo "<tr>  <td bgcolor=\"#00CCFF\">$TopLevel</td>
             <td>$category</td>                   
             <td>$offeringsname</td>             
             <td>$resnames</td></tr>";
the bgcolor usage is not recommended by W3C and it'll be deprecated soon. you'd better use a style or a css class instead of it...

Code: Select all

echo "<tr>  <td style=\"background-color:#00CCFF\" >$TopLevel</td>
             <td>$category</td>                   
             <td>$offeringsname</td>             
             <td>$resnames</td></tr>";

Posted: Thu Sep 06, 2007 3:16 am
by CoderGoblin
You may want to look at the following link... PHP Manual Strings. You have three alternatives when producing strings. Double quoted ", Single quoted ', and something called a Heredoc syntax. All three can be useful depending on your requirements.