2

I have a generated php table which I would like to apply style in my style sheet, so for example top:15px, left:10px ect..., not sure how call the table and link it with css -

echo "<table border=1>";
for ($i=0;$i<count($calls);$i++){
  for ($j=0;$j<count($days);$j++){
    $k = $days[$i].$times[$j];
    if (array_key_exists($k,$date)){
      echo "<td colspan='{$date[$k][1]}'>".
           "{$date[$k][0]}</td>";
      $j+=$date[$k][1]-1;
    }else
      echo "<td style='color:gray'>$k</td>";
  }

  echo "</tr>";
}
echo "</table>";

any help much appreciated, thank you

4
  • 1
    did you include a css file somewhere in the head of your document? Commented Apr 16, 2012 at 14:17
  • Which part do you not know how to do: Add a stylesheet to your page? Modify this PHP to include classes or ids on the table? Modify your CSS to apply to this table? Commented Apr 16, 2012 at 14:18
  • table td or table tr or by class or by ID, what exactly do you need? Commented Apr 16, 2012 at 14:20
  • Damien - I would like to have control over the whole table Commented Apr 16, 2012 at 15:47

4 Answers 4

3
echo '<table style="top: 15px; left:10px;">';

or

echo '<table class="someClass">';

and then use CSS

.someClass{
top: 15px;
left: 10px;
}
Sign up to request clarification or add additional context in comments.

Comments

3

Give the table an id

echo "<table id=\"my_table\" border=1>";

And then use this in the <head> tag of the document:

<style type="text/css">

  #my_table {
    top: 15px;
    ...
  }

</style>

1 Comment

I can see a syntax-error in the PHP part of your answer from a mile away :)
0
echo "<table style=\"border: 1px; top:15px; left: 10px;\">";

Is this statement not working?

Comments

0
echo "<table border=1 style=\"top:15px; left:10px\">";

for ($i=0; $i<count($calls); $i++) {
    for ($j=0;$j<count($days);$j++) {
        $k = $days[$i].$times[$j];

        if (array_key_exists($k,$date)) {
            echo "<td colspan='{$date[$k][1]}'>".
                 "{$date[$k][0]}</td>";
            $j+=$date[$k][1]-1;
        } else {
            echo "<td style='color:gray'>$k</td>";
        }
    }

    echo "</tr>";
}

echo "</table>";

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.