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 echo "<table class="listing" cellpadding="0" cellspacing="0">";.

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=php]    <?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>";
				}



		?>[/code]

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

      I thought i would give a better answer.

      You need to escape your special characters. I.e. " is such a special character given the context.

      echo "<table cellpadding="0" cellspacing="0">";
      

      Becomes:

      echo "<table cellpadding=\"0\" cellspacing=\"0\">";
      

      For clean clean code you can also use:

      echo '<table cellpadding="0" cellspacing="0">';
      

      And another example:

      echo '<table style="' . $myStyle . '" cellpadding="0" cellspacing="0">';
      

        Hi

        Thanks for the reply.

        Could you please explain what .$myStyle. means? Is that a Css stored in php?

          When you're echoing with double quotes, any other double quote inside that string must be escaped (prepend a character with a backslash) - meaning "take this literally, don't interpret it".

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

          When using single quotes, you can have un-escaped double quotes.

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

          Also, there are several ways to concatenate or insert a variable intro a string:

          echo         '<td>' . $vendorname  .  '</td>';
          echo         "<td>" . $vendorname  .  "</td>";
          echo         "<td>$vendorname</td>"; // PHP interprets variables inside double quotes
          echo         "<td>" , $vendorname  ,  "</td>";  // you can use commas also
          echo         "<td>{$vendorname}</td>";
          
          // using HEREDOC syntax
          echo $string =<<<WHATEVER
          <td>$vendorname</td>
          <td>$contactperson</td>
          <td>$type</td>
          <td>$contactaddress</td>
          WHATEVER;
          

          I'm just taking my time to explain this because I was in your small shoes not long ago, otherwise I would say something like "hey, pal, do learn the basics, will ya?". Google "concatenation php".

          LE: Didn't saw the above posts. I'm just repeating what neilmasters said.

            Hi

            Thanks for your time and patience.

              Bbob;10960536 wrote:

              Hi

              Thanks for the reply.

              Could you please explain what .$myStyle. means? Is that a Css stored in php?

              Just thought I would add on to this as i did not see it answered.

              $myStyle is simply an example i used to show how to use a variable within concatenation of '' instead of "".

              I.e.

              $tableStyle = "padding: 10px;";
              $tdStyle = "padding: 0.3em;";
              
              echo '<table style="' . $tableStyle . '" cellpadding="0" cellspacing="0">';
              echo '<tr>';
              echo '<td style="' . $tdStyle . '">Bob</td>';
              echo '</tr>';
              echo '</table>';
              
              echo '<table style="' . $tableStyle . '" cellpadding="0" cellspacing="0">';
              echo '<tr>';
              echo '<td style="' . $tdStyle . '">Dave</td>';
              echo '</tr>';
              echo '</table>';
              

              So if you changed $tdStyle or $tableStyle at the top, it would effect the following two tables.

                Write a Reply...