[SOLVED] How do you post a html table tag inside a PHP tag?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bbob
Forum Commoner
Posts: 57
Joined: Sat Aug 07, 2010 4:46 am

[SOLVED] How do you post a html table tag inside a PHP tag?

Post by Bbob »

Hi

How do you write a html table tag with class with modifications in a PHP tag?


Here my code. I keep getting a Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\hp\admin_vendor.php on line 10.

Note, this is not whole code but only the PHP Tag. If you need the whole code let me know and Ill post it. Another thing, Im using CSS on my html tables.

Code: Select all

         <?php

					mysql_connect("localhost", "root", "") or die(mysql_error()); 
					mysql_select_db("hp") or die(mysql_error()); 

					$sql=mysql_query("SELECT * FROM vendorinfo");


								
						echo		"<table class="listing" cellpadding="0" cellspacing="0">";
						echo				"<tr>";
						echo					"<td>" Vendor Name 	"</td>";
						echo					"<td>" Contact Person "</td>";
						echo					"<td>" Type			"</td>";
						echo					"<td>" Contact Number "</td>";
						echo				"</tr>";
									
	
							
	
				while ($row = mysql_fetch_assoc($sql))
					{
						$vendorname = $row['vendorname'];
						$contactperson = $row['contactperson'];
						$type = $row['type'];
						$contactnumber = $row['contactaddress'];
						
						echo 	"<tr>";
						echo 		"<td>" $vendorname 	   "</td>";
						echo 		"<td>" $contactperson  "</td>";
						echo 		"<td>" $type           "</td>";
						echo 		"<td>" $contactaddress "</td>";
						echo 	"</tr>";
						
						echo	"</table>";
					}
			


			?>
Last edited by Bbob on Thu Aug 12, 2010 3:14 am, edited 1 time in total.
Steji
Forum Newbie
Posts: 19
Joined: Fri Jun 18, 2010 6:06 am

Re: How do you post a html table tag inside a PHP tag?

Post by Steji »

It looks like you need to escape your quotes within the echo.

Code: Select all

echo  "<table class=\"listing\" cellpadding=\"0\" cellspacing=\"0\">";
Just put backslashes in there.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: How do you post a html table tag inside a PHP tag?

Post by shawngoldw »

You've almost got it.

I'll just show you a few of the errors and you can fix the rest.

Code: Select all

echo "<table class="listing" cellpadding="0" cellspacing="0">";
needs to be

Code: Select all

echo "<table class='listing' cellpadding='0' cellspacing='0'>";
or

Code: Select all

echo "<table class=\"listing\" cellpadding=\"0\" cellspacing=\"0\">";
What's happening here is when you put the first " to indicate the start of a string, php looks for the next " to be the end of the string and expects a ; after the string. To php the string ends just before the word listing, because php will think the string is only this: "<table class="

You can fix this by either using a single quote so that the string does not end, or by using a backslash infront of the double quote to tell php to ignore the double quote and only print it, not end the string.


This:

Code: Select all

echo "<td>" $vendorname "</td>";
needs to become:

Code: Select all

echo "<td>" . $vendorname . "</td>";
The dots tell php to concatinate the different parts of the string. For more details on this just look up php concatination.

Hope this helps,
Shawn
Bbob
Forum Commoner
Posts: 57
Joined: Sat Aug 07, 2010 4:46 am

Re: How do you post a html table tag inside a PHP tag?

Post by Bbob »

Hi

Thanks for the help its working now :D
Post Reply