|
Posted by Rik on 10/19/06 05:38
toffee wrote:
> thanks everyone for the suggestions and I didnt mean to start an
> argument :-/
>
> Steve - apologies for not making it clearer, but when a user clicks
> on a cell the page is indeed refreshed; i just wanted to be able to
> show which cell caused the refresh by highlighting it.
Well, let me say that first of all when displaying certain data above in a
table, on which the data below depends, I cannot imagine how it's not
possible to use a simple:
for(table_cells loop)}
$class = (selected) ? ' class="selected"':'';
echo "<td{$class}>".$some_value().'</td>';
}
But hey:
Requirements:
1. You buffer your table in variable $table, no direct output.
2. x- and y-coφrdinates are known.
3. No rowspan or colspan in sight.
4. Classnames are correctly quoted with "";
5. Attribut names or values never hold the invalid '>' (should he < if
desired).
Use only on own tables with ensured above properties.
Example, I'm not testing this, so there are possible type-errors:
---CSS---
td.higlight{
background-color: yellow;
}
---PHP---
$table = //the table as you made it.
$x = //the x coordinate
$y = //the y coordinate
$regex = '|(<table.*?)
((<tr[^>]*>.*?</tr>.*?){'.($y-1).'}) #all previous rows
((<td[^>]*>.*?</td>.*?){'.($x-1).'}) #all previous cells
<td #target cell
([^>])*? #random attributes
(\s*class="([^"])*")? #perhaps existing classvalue
([^>])*? #random attributes
>|six';
$table = preg_replace($regex,'$1$2$4<td$6 class="highlight $8"$9>',$table);
/x is underestimated in regexes :-)
--
Grtz,
Rik Wasmus
[Back to original message]
|