954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help with HTMl Table echoing?

Hi, I need som assistance placeing an HTML table within a PHP script. I thought I could just echo it, but I am getting a parse error. Here is the PHP code: (the parse error comes on line 339 <?php /* declare some relevant variables */ $DBhost = "localhost"; $DBuser = "username"; $DBpass = "password"; $DBName = "allin1em_catalog"; $table = "items"; mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "SELECT * FROM $table WHERE store = 'Luminescents'"; $result = mysql_query($sqlquery); while($row = mysql_fetch_array($result)) { echo "". $row[title] . "
<a href=http://www.allin1emall.com/images/ ". $row[thumb]. " title=" alt="" style="width: 150px; height: 150px;">
". $row[description]. "
". $row[retail]. " ".; } if(mysql_num_rows($result)<1){ echo "No Results!
"; } mysql_free_result($result); ?> Any help will be much appreciated. Thanks, Traci

sistrlynn
Newbie Poster
2 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0
 

Oopps, since this isn't the full page with the entire code you have no idea which is line 339. It is either the while line of the echo line right after it. Hope that helps.

sistrlynn
Newbie Poster
2 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0
 

[php]
echo "
[/php]

The problem is that you're using double quotes inside double quotes (and you also forgot to end the statement properly). PHP thinks you've finished echoing, when you obviously haven't. Just change the outer pair to single quotes, like so:

[php]
echo '
[/php]

and obviously the closing ".; to '; (why was that . there in the first place??)

Another solution is slightly simpler - get rid of the echo altogether, and close the php with ?> just before your table code, and <?php again afterwards.

Infact, I recommend you only use double quotes when neccessarily, as they add to execution time - the difference is as follows:

[php]
$var = 'cool';
echo "The var is: $var"; // It returns: The Var is: cool
echo 'The var is: $var'; // It returns: The Var is: $var
[/php]

So, with double quotes, the parser checks for any variables inside, which very slightly slows things down.

Roberdin
Supreme Evil Overlord
Team Colleague
282 posts since Feb 2003
Reputation Points: 63
Solved Threads: 6
 

You can also do this:

[PHP] echo "";[/PHP]

Just sick a \ infrong of a PHP character you don't want to do anything so like $, ", ' etc change to \$, \", \' etc and the PHP engine will just treat them like any normal character while removing the \

Ragnarok
Junior Poster in Training
94 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0
 

For large blocks of HTML, I just close the php block and use regular HTML. If I have to do output of a PHP variable, I just use <?=$variable?>.

samaru
a.k.a inscissor
Team Colleague
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
 

just keep in mind one thing before echo any html tag

use "" then all the properties of this tag will ""

and vice versa.

you will never get any error!

akvlko
Light Poster
31 posts since Oct 2009
Reputation Points: 10
Solved Threads: 1
 

Hi,

Just stop the php flow and start a normal html with quick php inserts.

like <?=$row[foo]?>

very handy :)

richieking
Master Poster
764 posts since Jun 2009
Reputation Points: 61
Solved Threads: 152
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You