| | |
Need help with HTMl Table echoing?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2004
Posts: 2
Reputation:
Solved Threads: 0
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 "<table cellpadding="2" cellspacing="2" border="1"
style="text-align: left; width: 400px;">
<tbody>
<tr>
<td
style="background-color: rgb(51, 51, 255); height: 25px; width: 400px; text-align: center; vertical-align: middle;"><span
style="color: rgb(153, 0, 0);"><span style="font-weight: bold;"><font
size="+1"><span style="font-family: arial;">". $row[title] .
"</span></font></span></span><br>
</td>
</tr>
</tbody>
</table>
<table cellpadding="2" cellspacing="2" border="1"
style="text-align: left; width: 400px;">
<tbody>
<tr>
<td
style="background-color: rgb(153, 153, 153); height: 150px; width: 150px; text-align: center; vertical-align: middle;"><img
src="http://www.allin1emall.com/images/". $row[thumb]. " title=" alt=""
style="width: 150px; height: 150px;"><br>
</td>
<td
style="text-align: center; vertical-align: middle; width: 250px; background-color: rgb(153, 153, 153); height: 150px;"><span
style="color: rgb(153, 0, 0);"><span style="font-weight: bold;"><font
size="+1"><span style="font-family: arial;">". $row[description]. "<br>". $row[retail]. "</span></font></span></span>
</td>
</tr>
</tbody>
</table>".;
}
if(mysql_num_rows($result)<1){
echo "<font face=Arial size=+0><b>No
Results!</b></font><br>";
}
mysql_free_result($result);
?>
Any help will be much appreciated.
Thanks,
Traci
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 "<table cellpadding="2" cellspacing="2" border="1"
style="text-align: left; width: 400px;">
<tbody>
<tr>
<td
style="background-color: rgb(51, 51, 255); height: 25px; width: 400px; text-align: center; vertical-align: middle;"><span
style="color: rgb(153, 0, 0);"><span style="font-weight: bold;"><font
size="+1"><span style="font-family: arial;">". $row[title] .
"</span></font></span></span><br>
</td>
</tr>
</tbody>
</table>
<table cellpadding="2" cellspacing="2" border="1"
style="text-align: left; width: 400px;">
<tbody>
<tr>
<td
style="background-color: rgb(153, 153, 153); height: 150px; width: 150px; text-align: center; vertical-align: middle;"><img
src="http://www.allin1emall.com/images/". $row[thumb]. " title=" alt=""
style="width: 150px; height: 150px;"><br>
</td>
<td
style="text-align: center; vertical-align: middle; width: 250px; background-color: rgb(153, 153, 153); height: 150px;"><span
style="color: rgb(153, 0, 0);"><span style="font-weight: bold;"><font
size="+1"><span style="font-family: arial;">". $row[description]. "<br>". $row[retail]. "</span></font></span></span>
</td>
</tr>
</tbody>
</table>".;
}
if(mysql_num_rows($result)<1){
echo "<font face=Arial size=+0><b>No
Results!</b></font><br>";
}
mysql_free_result($result);
?>
Any help will be much appreciated.
Thanks,
Traci
•
•
Join Date: Feb 2003
Posts: 282
Reputation:
Solved Threads: 6
[php]
echo "<table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 400px;">
[/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 '<table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 400px;">
[/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.
echo "<table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 400px;">
[/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 '<table cellpadding="2" cellspacing="2" border="1" style="text-align: left; width: 400px;">
[/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.
•
•
Join Date: Mar 2004
Posts: 94
Reputation:
Solved Threads: 0
You can also do this:
[PHP] echo "<table cellpadding=\"2\" cellspacing=\"2\" border=\"1\"
style=\"text-align: left; width: 400px;\">";[/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 \
[PHP] echo "<table cellpadding=\"2\" cellspacing=\"2\" border=\"1\"
style=\"text-align: left; width: 400px;\">";[/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 \
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?>.
Check out my blog at http://www.shinylight.com for more stuff about web dev.
![]() |
Similar Threads
- how to get the row id of the clicked row in a HTML table using c# (C#)
- How to change the color of selected row of an HTML table without using CSS or Javascr (VB.NET)
- get HTML table property on page load event (ASP.NET)
- cfgrid inside an HTML table... possible? (ColdFusion)
- Navigation (Paging) in HTML table in VB.NET. (VB.NET)
- HTML table vertical aligning problem (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Help with a script
- Next Thread: Getting Contents Inbetween
| Thread Tools | Search this Thread |
# 5.2.10 access action address alexa apache api array auto autoincrement broken cakephp checkbox class classes clean clients cms code cron curl database date dehasher destroy directory dissertation domain dropdown dynamic echo$_get[x]changingitintovariable... email encode error errorlog fairness fatalerror file folder form function functions google href htaccess html image include indentedsubcategory ip javascript joomla legislation limit link load local login masterthesis memberships menu multiple multipletables mysql mysqlquery newsletters oop open passwords paypal pdf persist php popup provider query radio random script search secure server sessions simple sockets source space spam sql system table tutorial upload url user variable voteup web youtube






