| | |
html table in php code.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 14
Reputation:
Solved Threads: 0
Dear friend,
I can't find the syntax error in my html table in php code.
many thanks in advance,
regards.
ko
I can't find the syntax error in my html table in php code.
PHP Syntax (Toggle Plain Text)
echo "<table border='1'>"; echo"<tr>"; echo"<th>".{$data['engword']}."</td>"; echo"<th align='left'> "<a href=\"http://www.domain.com/sound/En-us-{$data['engword']}.WAV \" title=\"open the audio file for the word {$data['engword']} \"rel='dbPopWin'><img src='audio.gif'></a>"."</td>"; echo"</tr>"; echo"<tr>"; echo"<td align='left'></td>"; echo"<td>".(stripslashes($data["mword"]))."</td>"; echo"</tr>"; echo"</table>";
many thanks in advance,
regards.
ko
Error is:
and you don't need () around the stripslashes function.
PHP Syntax (Toggle Plain Text)
echo"<th>".{$data['engword']}."</td>";
and you don't need () around the stripslashes function.
With so much html and so little php, perhaps you'd be better off 'reversing' the coding. Your code:
You've gotta lot of xhtml errors above (e.g. content inside <th> and </td>; single quotes around attribute values instead of doubles.)
Change this to:
The '<?=' is shorthand for '<?php echo '. This may be frowned upon by some developers, but if your setup supports short tags (it should), then it's a time saver.
Again many developers would frown at mixing xhtml and raw php code like this, but what the hell? You're only creating a basic link list.
I think that keeping to 'normal' xhtml as much as possible and just inserting the odd bit of 'php echo code' can see you OK. Once you start with all those
PHP Syntax (Toggle Plain Text)
echo "<table border='1'>"; echo"<tr>"; echo"<th>".{$data['engword']}."</td>"; echo"<th align='left'> "<a href=\"http://www.domain.com/sound/En-us-{$data['engword']}.WAV \" title=\"open the audio file for the word {$data['engword']} \"rel='dbPopWin'><img src='audio.gif'></a>"."</td>"; echo"</tr>"; echo"<tr>"; echo"<td align='left'></td>"; echo"<td>".(stripslashes($data["mword"]))."</td>"; echo"</tr>"; echo"</table>";
You've gotta lot of xhtml errors above (e.g. content inside <th> and </td>; single quotes around attribute values instead of doubles.)
Change this to:
PHP Syntax (Toggle Plain Text)
<table border="1"> ...include <thead> bits... <tbody> <?php while($data = mysql_fetch_array('result'){ ?> <tr> <td><?=$data['engword'];?></td> <td align="left"><a href= "http://www.domain.com/sound/En-us-<?={$data['engword']};?>.wav" title="open the audio file for the word <?=$data['engword'];?>" rel="dbPopWin"><img src= "audio.gif"></a></td> </tr> <tr> <td align="left"> </td> <td><?=stripslashes($data["mword"]);?></td> </tr> <?php } ?> </tbody> </table>
The '<?=' is shorthand for '<?php echo '. This may be frowned upon by some developers, but if your setup supports short tags (it should), then it's a time saver.
Again many developers would frown at mixing xhtml and raw php code like this, but what the hell? You're only creating a basic link list.
I think that keeping to 'normal' xhtml as much as possible and just inserting the odd bit of 'php echo code' can see you OK. Once you start with all those
\" escaped quotes, things can become very messy. "...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Where does it say that you have to use double quotes? I ran a check through w3.org validator and there were no xhtml errors concerning single quotes.
I am one of those developers who frowns upon mixing html and php (and using short tags). I suggest you use heredoc syntax.
echo <<<HTML
//put html here use {$var} to include variables.
HTML;
That way you can write html code like normal and it still uses php.
I am one of those developers who frowns upon mixing html and php (and using short tags). I suggest you use heredoc syntax.
echo <<<HTML
//put html here use {$var} to include variables.
HTML;
That way you can write html code like normal and it still uses php.
Last edited by kkeith29; May 26th, 2009 at 3:50 pm.
•
•
Join Date: May 2009
Posts: 14
Reputation:
Solved Threads: 0
thanks you for your hint with xhtml and php syntax guide.
It is embarrassing to ask you again.., but I need to know how I can better clean my code.
I dont have still result from my search.php
search.php
best regards,
koko
It is embarrassing to ask you again.., but I need to know how I can better clean my code.
I dont have still result from my search.php
search.php
PHP Syntax (Toggle Plain Text)
<body> <table border="1"> <?php $db_name="dic"; trim($searchterm); if (!$HTTP_GET_VARS["searchterm"]) { echo "You haven't entered any word to search.Please, go back and entered it."; exit; } $searchterm = addslashes($searchterm); require("dict.php"); if (!$db) { echo "Error. Can't connect to database.Please try later"; } mysql_select_db($db_name); $query = "select * from dic where engword like '".$HTTP_GET_VARS["searchterm"]."%' order by engword"; $result = mysql_query($query); $num_results = mysql_num_rows($result); ?> <tbody> <?php while($data = mysql_fetch_array('result')){ ?> <tr> <td><?=$data['engword'];?></td> <td align="left"><a href= "http://www.domain.com/sound/En-us-<?={$data['engword']};?>.wav" title="open the audio file for the word <?=$data['engword'];?>" rel="dbPopWin"><img src= "audio.gif"></a></td> </tr> <tr> <td align="left"> </td> <td><?=stripslashes($data["mword"]);?></td> </tr> <?php } ?> </tbody> </table> <?php echo mysql_close($db); ?> <a href='index.php'>search another word</a> </body> </html>
best regards,
koko
Last edited by sayakyi; May 26th, 2009 at 4:32 pm.
Damn! Meant to edit the last post.
@KK
Sorry KK, that sounded a bit rude. The heredoc syntax, I will concede is a better way if there's loads of text/html and the occasional php variable to insert. However, if you need to stripslash or whatever, it gets a bit messy, or you have to transform before the heredoc and then insert the vars.
@Say
Sorry fella, I'm a bit busy at the moment. I don't think you're far off with that code. Just play with it, try to isolate errors, change single lines at a time, etc.
@KK
Sorry KK, that sounded a bit rude. The heredoc syntax, I will concede is a better way if there's loads of text/html and the occasional php variable to insert. However, if you need to stripslash or whatever, it gets a bit messy, or you have to transform before the heredoc and then insert the vars.
@Say
Sorry fella, I'm a bit busy at the moment. I don't think you're far off with that code. Just play with it, try to isolate errors, change single lines at a time, etc.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
•
•
Join Date: Apr 2009
Posts: 254
Reputation:
Solved Threads: 37
if you code's most of the part is html then you should use php with in html tags but if your php part is more then html then use html in php qoutes.
There are a few web pages setup to do this for us... here is one of them:
http://corz.org/machine/source/php/tag-tools.php
http://corz.org/machine/source/php/tag-tools.php
www.beeerlover.org <- my hobby with 15K+ Pink Floyd Images
www.bestbridalprices.com <- my job with 15K+ Wedding Dresses
www.bestbridalprices.com <- my job with 15K+ Wedding Dresses
![]() |
Similar Threads
- How to View and Edit data in same table - PHP Script (PHP)
- Help:Convert HTML Table in to Text File Using PHP (PHP)
- Passing html array to php (PHP)
- HTML codes in PHP (PHP)
- Using HTML tags in PHP code (PHP)
- error parsing php code (PHP)
- PHP code not blending with HTML (PHP)
- Need help with HTMl Table echoing? (PHP)
Other Threads in the PHP Forum
- Previous Thread: require_once overhead???
- Next Thread: help in Php n exts..
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend






