How to generate ids for tables made by php

I am trying to create a page to allow toggling on and off certain forums in website, created from raw data in an SQL server. However I need each to have an individual ID so I can show/hide them based on user preference. I am not sure how to go about it. Here is my existing code, disregard the connection values, I am hiding them on purpose. thanks.

$db_host = "host";
$db_username = "username";
$db_pass = "pass";
$db_name = "name";
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$query = $db->query('SELECT p.name, p.company, o.prodtype AS Type
FROM ownedproducts AS o
JOIN product as p ON p.productID = o.productID
WHERE o.usersID = 2');
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title> User Forum Selection </title>
</head>
<body>
    <div>
<input type="text" id="userid">
    </div>
    <div>
<hr>
<table id=table border = '2'>
<tr id=table-row>
<th id=table-header>Name</th>
<th id=table-header>Company</th>
<th id=table-header>Type</th>
</tr>
    
        
<?php
while ($row = $query->fetch()) 
{
    echo "<tr id=table-row >";
    echo "<td>" . $row['name'] ."</td>";
    echo "<td>" . $row['company'] . "</td>";
    echo "<td>" . $row['Type'] . "</td>";
    echo "</tr>";
}
?>

</table>
</div>
</body>
</html>


Read more here: https://stackoverflow.com/questions/66270660/how-to-generate-ids-for-tables-made-by-php

Content Attribution

This content was originally published by JewGiOh at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: