html table in php code.

Reply

Join Date: May 2009
Posts: 14
Reputation: sayakyi is an unknown quantity at this point 
Solved Threads: 0
sayakyi sayakyi is offline Offline
Newbie Poster

html table in php code.

 
0
  #1
May 26th, 2009
Dear friend,

I can't find the syntax error in my html table in php code.
  1. echo "<table border='1'>";
  2. echo"<tr>";
  3. echo"<th>".{$data['engword']}."</td>";
  4. 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>";
  5. echo"</tr>";
  6. echo"<tr>";
  7. echo"<td align='left'></td>";
  8. echo"<td>".(stripslashes($data["mword"]))."</td>";
  9. echo"</tr>";
  10.  
  11. echo"</table>";

many thanks in advance,

regards.
ko
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: html table in php code.

 
0
  #2
May 26th, 2009
Error is:
  1. echo"<th>".{$data['engword']}."</td>";

and you don't need () around the stripslashes function.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 957
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: html table in php code.

 
0
  #3
May 26th, 2009
With so much html and so little php, perhaps you'd be better off 'reversing' the coding. Your code:

  1. echo "<table border='1'>";
  2. echo"<tr>";
  3. echo"<th>".{$data['engword']}."</td>";
  4. 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>";
  5. echo"</tr>";
  6. echo"<tr>";
  7. echo"<td align='left'></td>";
  8. echo"<td>".(stripslashes($data["mword"]))."</td>";
  9. echo"</tr>";
  10.  
  11. 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:

  1. <table border="1">
  2.  
  3. ...include <thead> bits...
  4.  
  5. <tbody>
  6. <?php
  7. while($data = mysql_fetch_array('result'){
  8. ?>
  9. <tr>
  10. <td><?=$data['engword'];?></td>
  11. <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>
  12. </tr>
  13. <tr>
  14. <td align="left">&nbsp;</td>
  15. <td><?=stripslashes($data["mword"]);?></td>
  16. </tr>
  17. <?php
  18. }
  19. ?>
  20. </tbody>
  21. </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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: html table in php code.

 
0
  #4
May 26th, 2009
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.
Last edited by kkeith29; May 26th, 2009 at 3:50 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 14
Reputation: sayakyi is an unknown quantity at this point 
Solved Threads: 0
sayakyi sayakyi is offline Offline
Newbie Poster

Re: html table in php code.

 
0
  #5
May 26th, 2009
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


  1. <body>
  2. <table border="1">
  3. <?php
  4. $db_name="dic";
  5.  
  6. trim($searchterm);
  7. if (!$HTTP_GET_VARS["searchterm"])
  8. {
  9. echo "You haven't entered any word to search.Please, go back and entered it.";
  10. exit;
  11. }
  12. $searchterm = addslashes($searchterm);
  13. require("dict.php");
  14. if (!$db)
  15. {
  16. echo "Error. Can't connect to database.Please try later";
  17. }
  18. mysql_select_db($db_name);
  19. $query = "select * from dic where engword like '".$HTTP_GET_VARS["searchterm"]."%' order by engword";
  20. $result = mysql_query($query);
  21. $num_results = mysql_num_rows($result);
  22. ?>
  23. <tbody>
  24. <?php
  25.  
  26. while($data = mysql_fetch_array('result')){
  27. ?>
  28.  
  29. <tr>
  30. <td><?=$data['engword'];?></td>
  31. <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>
  32. </tr>
  33. <tr>
  34. <td align="left">&nbsp;</td>
  35. <td><?=stripslashes($data["mword"]);?></td>
  36. </tr>
  37. <?php
  38. }
  39. ?>
  40. </tbody>
  41. </table>
  42. <?php
  43. echo mysql_close($db);
  44. ?>
  45. <a href='index.php'>search another word</a>
  46. </body>
  47. </html>

best regards,

koko
Last edited by sayakyi; May 26th, 2009 at 4:32 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 957
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: html table in php code.

 
0
  #6
May 26th, 2009
@KK frown away!
"...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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 957
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: html table in php code.

 
0
  #7
May 27th, 2009
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.
"...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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 254
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: html table in php code.

 
0
  #8
May 27th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 40
Reputation: beeerlover is an unknown quantity at this point 
Solved Threads: 6
beeerlover's Avatar
beeerlover beeerlover is offline Offline
Light Poster

Re: html table in php code.

 
0
  #9
May 27th, 2009
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
www.beeerlover.org <- my hobby with 15K+ Pink Floyd Images
www.bestbridalprices.com <- my job with 15K+ Wedding Dresses
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 957
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 126
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: html table in php code.

 
0
  #10
May 27th, 2009
That's nice, especially for newbies. However, I think we're starting to wander off the point for Sayakyi. Any luck yet?
"...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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC