results in an table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
z0rr0
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 1:22 am

results in an table

Post by z0rr0 »

hy to all
how do i do so my result (of an calculaton) wil be shown in table ???

here is a saple of the code that must apeare in the table :
}

echo "tabel siruri:<br>";
echo "$sir0<br>";
echo "$sir1<br>";
echo "$sir2<br>";
echo "$sir3<br>";
echo "$sir4<br>";
echo "$sir5<br>";
echo "$sir6<br>";
echo "$sir7<br>";
echo "$sir8<br>";
echo "$sir9<br>";
?>
thanks
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Maybe a introduction to html is something for you?
I found a nice one.... An Introduction to HTML
z0rr0
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 1:22 am

Post by z0rr0 »

hmm...so it works just like in html (i meen the <table .... > stuff is the same ) ? i am very new to php so...but i KNOW html :?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

PHP doesn't replace HTML - you still need to use that to markup the code - PHP just makes it possible to generate dynamic pages with markup and contents changed without the need of hundreds of static pages.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php only produces a stream of data, what ever it is ...php doesn't care about it.
By default (and until you change it) the content-type text/html is sent within the response-header, so usually the client should try to interpret the output as html; that's courtesy of the client but it will not notice the difference between

Code: Select all

echo '<html><body><pre>test</pre></body></html>';
and

Code: Select all

&lt;html&gt;&lt;body&gt;&lt;pre&gt;test&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;
because the output (and only the output is what the client gets) is (more or less) identical.
If you open your browser's source-view you will see the output of the script (ok, some headers e.g. with cookie-data might have been sent, too) and nothing more the client will see and/or interpret
z0rr0
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 1:22 am

Post by z0rr0 »

thanks a lto
z0rr0
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 1:22 am

Post by z0rr0 »

so something like this will work ????
echo "<table width="100%" cellspacing="0" cellpadding="0" border="0">";
echo "<tr>
<td>&nbsp;tabel siruri:</td>
</tr>";
echo "<tr>
<td>&nbsp;$sir0</td>
</tr>";

echo "$sir1<br>";
echo "$sir2<br>";
echo "$sir3<br>";
echo "$sir4<br>";
echo "$sir5<br>";
echo "$sir6<br>";
echo "$sir7<br>";
echo "$sir8<br>";
echo "$sir9<br>";
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

don't hesitate to try it ;)
echo "<table width="100%" cellspacing="0" cellpadding="0" border="0">";
if you start a string literal with a double quote php will parse anything up to next double quote as contents of the literal, but it will stop at the next ", so you will get a parse error. Take a look at the colors the syntax highlighter uses here

Code: Select all

echo "<table width="100%" cellspacing="0" cellpadding="0" border="0">";
echo "<tr>
<td> tabel siruri:</td>
</tr>";
echo "<tr>
<td> $sir0</td>
</tr>";
echo "$sir1<br>";
echo "$sir2<br>";
echo "$sir3<br>";
echo "$sir4<br>";
echo "$sir5<br>";
echo "$sir6<br>";
echo "$sir7<br>";
echo "$sir8<br>";
echo "$sir9<br>";
?>
As you can see the % of width="100%" has the same colour as the php-function echo, unlikely that this is correct ;)
But you can escape the special meaning of a character with backslashes; compare

Code: Select all

echo "<table width="100%" cellspacing="0" cellpadding="0" border="0">";
echo "<tr>
<td> tabel siruri:</td>
</tr>";
echo "<tr>
<td> $sir0</td>
</tr>";
echo "$sir1<br>";
echo "$sir2<br>";
echo "$sir3<br>";
echo "$sir4<br>";
echo "$sir5<br>";
echo "$sir6<br>";
echo "$sir7<br>";
echo "$sir8<br>";
echo "$sir9<br>";
?>
Now all string literals are monocoloured, as they should..

If you think this looks ugly I totally agree. If you do not need substitutions (like echo "and the winner is: $winner"; ) you can use single quote as delimeter

Code: Select all

echo '<table width="100%" cellspacing="0" cellpadding="0" border="0">';
echo '<tr>
<td> tabel siruri:</td>
</tr>';
echo "<tr>
<td> $sir0</td>
</tr>";
echo "$sir1<br>";
echo "$sir2<br>";
echo "$sir3<br>";
echo "$sir4<br>";
echo "$sir5<br>";
echo "$sir6<br>";
echo "$sir7<br>";
echo "$sir8<br>";
echo "$sir9<br>";
?>
there are some other styles but I think this should do for now ;)
Last edited by volka on Wed Jun 11, 2003 5:10 am, edited 1 time in total.
z0rr0
Forum Newbie
Posts: 7
Joined: Tue Jun 03, 2003 1:22 am

Post by z0rr0 »

thanks again
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

It's also worth giving the "Strings" manual page a read, which explains the use of quotes:

http://www.php.net/types.string

Regards,
Post Reply