Unique Id For Dynamic Table
I will be generating a HTML table with data pulled from MySQL.The number of rows in my MySQL table are not fixed. &l
Solution 1:
Why can't you do something like this ?
<?php$i = 1;
while($row=mysql_fetch_assoc($result))
{ ?><trid="row<?phpecho$i;?>"><tdid="cell-left-<?phpecho$i;?>"><?phpecho$row['col1'];?></td><tdid="cell-right-<?phpecho$i;?>"><?phpecho$row['col2'];?></td></tr><?php$i++;
} ?>
Please note, I have added ids row
, cell-left-
and cell-right-
by myself. You may change them as per your requirements.
Solution 2:
You can use a counter when iterating through the rows, maybe something like this:
<?php$rowCount = 0;
while($row=mysql_fetch_assoc($result))
{
$rowCount++;
?><trid="<?phpecho'row' . $rowCount;?>"><td><?phpecho$row['col1'];?></td><td><?phpecho$row['col2'];?></td></tr><?php
}
?>
You can now select an element with
var rowID = 1;
document.getElementById("row" + rowID);
Hope this helps.
Post a Comment for "Unique Id For Dynamic Table"