0

Image of table

I am using a table which embeded in echo php code. I am assigning a table class and styling of table but on web page is not effecting in table

<?php 
 echo "<table><tr><td>1. Entry Test</td><td>1 Hour</td></tr>
       <tr><td>2. Refreshments</td><td>30 Minutes</td></tr>
       <tr><td>3. Tour of campus Labs and Hanger Facility</td><td>1 
        Hour</td></tr>
       <tr><td>4. Interviews</td><td>(For all shortlisted candidates only)</td></tr></table>"";
?>

issue is that how to add class in this format. I am beginner in php development

table image 2

6
  • class for styling purpose for example <table class="settingtable"> Commented Nov 16, 2018 at 10:12
  • wait a mint I also add a pic of table what want margin-left in table but its not working and also a assign class still not working Commented Nov 16, 2018 at 10:14
  • 2
    @AhilKhan you can just escape your quotes: echo "<table class=\"settingtable\">" Commented Nov 16, 2018 at 10:15
  • 1
    If I understand you right you just need this <?php echo "<table class=\"settingtable\">....</table>"?> Commented Nov 16, 2018 at 10:15
  • Or even easier : <?php echo '<table class="settingtable">....</table>';?> Commented Nov 16, 2018 at 10:20

4 Answers 4

2

You can add class OR styling to your code as below:

echo "<table class='testTable' style='border:1px solid red;'><tr><td>1. Entry Test</td><td>1 Hour</td></tr>
       <tr><td>2. Refreshments</td><td>30 Minutes</td></tr>
       <tr><td>3. Tour of campus Labs and Hanger Facility</td><td>1 
        Hour</td></tr>
       <tr><td>4. Interviews</td><td>(For all shortlisted candidates only)</td></tr></table>";

In your code at end you have ""; which should only be ";

Sign up to request clarification or add additional context in comments.

Comments

2

This is probably preference but I never echo out HTML using double quotes. Using single quotes allows you to use double quotes in your HTML without escaping anything. I also structure my code so I can read it better.

Here is an example. I just added class="myTableClass" into your table div.

echo 
 '<table class"myTableClass">
    <tr>
      <td>1. Entry Test</td>
      <td>1 Hour</td>
    </tr>
    <tr>
      <td>2. Refreshments</td>
      <td>30 Minutes</td>
      </tr>
    <tr>
      <td>3. Tour of campus Labs and Hanger Facility</td>
      <td>1 Hour</td>
    </tr>
    <tr>
      <td>4. Interviews</td>
      <td>(For all shortlisted candidates only)</td>
    </tr>
  </table>';

A very basic CSS script looks like this:

body {
    background-color: lightblue;
}

h1 {
    color: white;
    text-align: center;
}

p {
    font-family: verdana;
    font-size: 20px;
}

.myTableClass {
  background-color: black;
  color: white;
  margin: 20px;
  padding: 20px;
}

You would name it something like mystyle.css and you would install it into your root directory.

Then in your webpage you would reference the CSS by including into your HTML. This is typically placed inside your <head> tag.

Like so:

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head> 

I took this example from w3schools. Here is a link for you to look at.
How to CSS

It looks like in your case you are trying to adopt a CSS that is currently used on your site. You will have to see where the css is installed in your directory and examine it for the table properties.

Another way to do it would be to examine a table that works like you want and look at the css class that is being used.

Hope it helps.

6 Comments

single quotes 100% of the time - they execute faster (by microseconds but still..)
Do you have a CSS script with a table class in it?
inspect a table on web page and there is no show a table class
@treyBake I agree with you 100%.
You need to install a CSS script into your directory and include it in your HTML script.
|
0

As you are concatenating the string with a double quote "" now you should use single quote '' to add the new attribute in table tags as:

<?php 
 echo "<table class='table_class_name' style='color:#444;'>
       <tr class='tr_class_name'><td>1. Entry Test</td><td>1 Hour</td></tr>
       <tr><td>2. Refreshments</td><td>30 Minutes</td></tr>
       <tr><td>3. Tour of campus Labs and Hanger Facility</td><td>1 
        Hour</td></tr>
       <tr><td>4. Interviews</td><td>(For all shortlisted candidates only)</td></tr></table>";
?>

Comments

0
    You can add like this. 
<?php 

$html = "<table class='asdfd'><tr><td>1. Entry Test</td><td>1 Hour</td></tr> <tr><td>2. Refreshments</td><td>30 Minutes</td></tr><tr><td>3. Tour of campus Labs and Hanger Facility</td><td>1 Hour</td></tr><tr><td>4. Interviews</td><td>(For all shortlisted candidates only)</td></tr></table>";

 echo $html;
?>

//with single quote 
    <?php 

    $html = '<table class="hti"><tr><td>1. Entry Test</td><td>1 Hour</td></tr>
           <tr><td>2. Refreshments</td><td>30 Minutes</td></tr>
           <tr><td>3. Tour of campus Labs and Hanger Facility</td><td>1 
            Hour</td></tr>
           <tr><td>4. Interviews</td><td>(For all shortlisted candidates only)</td></tr></table>';

    echo $html;
    ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.