Page 1 of 1

how to add a table ?

Posted: Sat Jun 21, 2003 5:29 pm
by GK
how do i put a complete table in here?

<?
if(strlen($site_rtttl)>260) {
echo "Deze bevat meer dan 50 tonen";
} else {
echo "Deze ringtone is helemaal gratis!";
}
?>


like this

<?
if(strlen($site_rtttl)>260) {
echo "<table width="85%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td class="tekst">
<div align="center"><a href="http://www.ringtone-zone.nl/top/rate.php?site=<? echo $id; ?>"><img src="vote.gif" width="150" height="40" border="0"></a></div>
</td>
<td class="tekst">
<div align="center"><a href="http://www.ringtone-zone.nl/top/recommend.php?site=<? echo $id; ?>"><img src="mail.png" width="150" height="40" border="0"></a></div>
</td>
<td class="tekst">
<div align="center"><a href="http://www.ringtone-zone.nl/top/review.php?site=<? echo $id; ?>"><img src="review.png" width="150" height="40" border="0"></a></div>
</td>
</tr>
</table>";
} else {
echo "Deze ringtone is helemaal gratis!";
}
?>

Posted: Sat Jun 21, 2003 7:44 pm
by volka
if you start a string literal with a double quote you have to escape double quotes within the contents. Php will stop the literal at the next unescaped double quote, e.g.
echo "<table width="85%" border="0" cellspacing="0" cellpadding="0" align="center">
php will only take "<table width=" as literal trying to parse 85% as the next statement (which doesn't work). Escaping the special meaning of a character is done by prepending a \

Code: Select all

&lt;?php ...
echo "&lt;table width="85%" border="0" cellspacing="0" cellpadding="0" align="center"&gt;"
... ?&gt;
Within double quoted literals variables are substituted, e.g.

Code: Select all

<?php
$myVar = '12345';
echo "the value of myVar is: $myVar";
?>
as long as you do not need this feature you might use single quoted literals and use " in there freely, e.g.

Code: Select all

<?php ...
echo '<table width="85%" border="0" cellspacing="0" cellpadding="0" align="center">';
...
?>
<? echo $id; ?>
this does not work when you're inside a literal. But you might leave the php block. Anything outside a php-block is sent as-is to the client.
take a look at these three examples (that should do almost the same but are untested)

Code: Select all

<?php // double quoted literals
$myVar = 'just an example';
echo "<table width="100%">
	<tr>
		<td>$myVar</td>
	</tr>
</table>";
?>

Code: Select all

<?php // single quoted literals
$myVar = 'just an example';
// echo can take multiple arguments, each added to the output stream
echo '<table width="100%">
	<tr>
		<td>', $myVar, '</td>
	</tr>
</table>';
?>

Code: Select all

<?php // leaving the php-block for (almost) static html
$myVar = 'just an example';
?>
<table width="100%">
	<tr>
		<td><?php echo $myVar; ?></td>
	</tr>
</table>
I prefer the last one...


see also: http://www.php.net/manual/en/language.types.string.php

Posted: Sat Jun 21, 2003 8:32 pm
by GK
i got the table working

but when i isert the rtttl url it goes wrong

<?
if(strlen($site_rtttl)>200) {
echo '<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#000000">
<tr>
<td class="tekst3b">
<div align="center"> <font color="#0000FF"> <font size="4" color="#FF0000">WAARSCHUWING!<br>
<font color="#000000" size="2">Deze ringtone bevat
meer dan 50 tonen<br>
Bij een aantal telefoons kun je deze niet helemaal
invoeren<br>
Maar wees gerust met <b><a href="javascript:mobilemoneysale('<? echo $site_rtttl ?>','<? echo $site_naam ?>')" target="_self"><font size="3" color="#FF0000">verzenden</font></a></b>
krijg je het wel helemaal </font></font></font></div>
</td>
</tr>
</table>';
} else {
echo "";
}
?>

Posted: Sat Jun 21, 2003 9:33 pm
by volka
take a look at how this looks if passed through the syntaxhighlighter

Code: Select all

<?
if(strlen($site_rtttl)>200) { 
echo '<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#000000">
                          <tr> 
                            <td class="tekst3b"> 
                              <div align="center"> <font color="#0000FF"> <font size="4" color="#FF0000">WAARSCHUWING!<br>
                                <font color="#000000" size="2">Deze ringtone bevat 
                                meer dan 50 tonen<br>
                                Bij een aantal telefoons kun je deze niet helemaal 
                                invoeren<br>
        Maar wees gerust met <b><a href="javascript:mobilemoneysale('<? echo $site_rtttl ?>','<? echo $site_naam ?>')" target="_self"><font size="3" color="#FF0000">verzenden</font></a></b> 
        krijg je het wel helemaal </font></font></font></div>
                            </td>
                          </tr>
                        </table>'; 
} else { 
echo ""; 
} 
?>
looks strange, doesn't it?
Let's start with something simple, a static html

Code: Select all

&lt;html&gt;
	&lt;head&gt;&lt;title&gt;an example&lt;/title&gt;&lt;/head&gt;
	&lt;body&gt;
		&amp;nbsp;
	&lt;/body&gt;
&lt;/html&gt;
now add some php

Code: Select all

<html>
	<head><title>an example</title></head>
	<body>
		<?php echo phpversion(); ?>
	</body>
</html
the <?php ?> tags tell the parser that what's inside is php. Everything outside will be passed as-is. Note the different colours used. Black is as-is output.
When you're in a php-block there's no nedd to open another block (in fact it's not allowed)

Code: Select all

<?php
/** This won't work */
echo 'something', <?php echo $something; ?>;
?>
see that the second ?> is black - the parser is confused...

Within a single quoted literal you have to escape single quotes if they are part of the contents. The same as with double quotes in a double quoted literal. There's no magic that tells php what you want to be in- and outside a literal - except syntax ;)

it's probably easier to leave the php-block here and re-enter it when needed

Code: Select all

<?php
if(strlen($site_rtttl)>200) {
?>
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#000000">
	<tr>
		<td class="tekst3b">
			<div align="center">
				<font color="#0000FF">
					<font size="4" color="#FF0000">WAARSCHUWING!<br /></font />
				</font>
				<font color="#000000" size="2">
					Deze ringtone bevat meer dan 50 tonen<br />
					Bij een aantal telefoons kun je deze niet helemaal invoeren<br />
					Maar wees gerust met
					<b>
						<a href="javascript:mobilemoneysale('<?php echo $site_rtttl; ?>,<?php echo $site_naam; ?>');" target="_self">
							<font size="3" color="#FF0000">verzenden</font>
						</a>
					</b>
					krijg je het wel helemaal
				</font>
			</div>
		</td>
	</tr>
</table>
<?php
} else {
	echo "";
}
?>
(maybe I messed with the font tags)

Posted: Sun Jun 22, 2003 6:19 am
by GK
i see what you mean now i think

i have to seperate it

<? php here ?>
html

<? php here ?>

html

Posted: Sun Jun 22, 2003 8:07 am
by volka
oh, there's one more thing I shouldn't keep back only because of preference for leaving php-blocks ;)
http://www.php.net/manual/en/language.t ... ax.heredoc

Code: Select all

<?php
$site_rtttl = str_repeat('abcd', 90);
$site_naam = 'blub';

if(strlen($site_rtttl)>200) {
echo <<<EOD
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#000000">
   <tr>
      <td class="tekst3b">
         <div align="center">
            <font color="#0000FF">
               <font size="4" color="#FF0000">WAARSCHUWING!<br /></font />
            </font>
            <font color="#000000" size="2">
               Deze ringtone bevat meer dan 50 tonen<br />
               Bij een aantal telefoons kun je deze niet helemaal invoeren<br />
               Maar wees gerust met
               <b>
                  <a href="javascript:mobilemoneysale('$site_rtttl','$site_naam');" target="_self">
                     <font size="3" color="#FF0000">verzenden</font>
                  </a>
               </b>
               krijg je het wel helemaal
            </font>
         </div>
      </td>
   </tr>
</table>
EOD;
} else {
   echo "";
}
?>
But that doesn't seperate php from html. Do you see where your php-variables are needed? It's all blue now :(

;)

Posted: Sun Jun 22, 2003 11:57 am
by GK

Code: Select all

<?php 
$site_rtttl = str_repeat('abcd', 90); 
$site_naam = 'blub'; 

if(strlen($site_rtttl)>200) { 
echo <<<EOD 
<table width="95%/" border="0/" cellspacing="0"/ cellpadding="0/" align="center/" bordercolor="#000000/"> 
   <tr> 
      <td class="tekst3b/"> 
         <div align="center/"> 
            <font color="#0000FF"/> 
               <font size="4/" color="#FF0000/">WAARSCHUWING!<br /></font /> 
            </font> 
            <font color="#000000/" size="2/"> 
               Deze ringtone bevat meer dan 50 tonen<br /> 
               Bij een aantal telefoons kun je deze niet helemaal invoeren<br /> 
               Maar wees gerust met 
               <b /> 
                  <a href="javascript:mobilemoneysale('$site_rtttl','$site_naam');" target="_self"> 
                     <font size="3" color="#FF0000">verzenden</font> 
                  </a> 
               </b> 
               krijg je het wel helemaal 
            </font> 
         </div> 
      </td> 
   </tr> 
</table> 
EOD; 
} else { 
   echo ""; 
} 
?>

Posted: Sun Jun 22, 2003 11:59 am
by GK
sorry clickt 2 times

Posted: Sun Jun 22, 2003 12:00 pm
by GK
mm i'm not really ge4tting the clue

Posted: Sun Jun 22, 2003 12:07 pm
by GK
i will print that page a read it carefully