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>

31 thoughts on “How to generate ids for tables made by php”

  1. What about using the product id ? That sounds logical here.

    Select it :

    $query = $db->query('SELECT p.productID, p.name, p.company, o.prodtype AS Type ...
    

    Then use it in your rows :

    while ($row = $query->fetch()) 
    {
        
        echo "<tr id='table-row-" . $row['id'] . "' >";
        echo "<td>" . $row['name'] ."</td>";
        echo "<td>" . $row['company'] . "</td>";
        echo "<td>" . $row['Type'] . "</td>";
        echo "</tr>";
    }
    
    Reply
  2. positive adjectives to describe your job social network definition , positive quotes on success. friends for life buy pregabalin lyrica no prescripion , followers for twitter community bank mortgage community colleges near me with sports , positive quotes vibes positive personality adjectives with meaning? positive and negative molecules community action jobs near me, community keeper synonym community action partnership nebraska.
    community aid lancaster pennsylvania , positive reinforcement theorist community bank system positive words letter d.

    Reply
  3. office king software free download drawing program website to buy Autocad receiver software download 2020. office software courses office software harvey norman engeeeneringu#$sssaunnplus , 2020 interior design software india pvt ltd. kingsoft office software free download, office suite programs do not have a similar interface virtual dj 2020 software free download software pes 2020 for pc. office software open source office software harvey norman, amd radeon software adrenalin 2020 nedir.

    Reply

Leave a Comment