Free tools Windows power users keep installed
One-click scans. No signup required.
Put an HTML <a> element inside the table cell, use the current row’s unique ID in its URL, and make the linked text the company name. The detail page must read the same query parameter and use it to load the record.
How do you add an href to a PHP table cell?
PHP generates the HTML; the link itself is a regular HTML anchor. If each result row contains an id and a compname, and readcompany.php expects an id query parameter, you can output the cell like this:
echo '<td><a href="readcompany.php?id=' . rawurlencode((string) $row['id']) . '">' .
htmlspecialchars($row['compname'], ENT_QUOTES, 'UTF-8') .
'</a></td>';
The company name is the link label; the ID determines which record the link opens. Keep those roles separate. For the link to work, the names and parameter in the example must match your application.
Make the table and detail page agree
The table constructs a URL such as readcompany.php?id=42. The receiving page needs to read id from the query string and use it to retrieve that company. PHP exposes query-string values through $_GET.
#1 Best Overall
$id = $_GET['id'] ?? null;
That line only retrieves the input; it does not validate it or fetch a record. Check that the value is present and valid for your application’s ID type and range before using it in a database query. The parameter name must match on both sides: if the URL uses ?id=, the detail page should read $_GET['id'].
Check the result row if the link breaks
Use a key that is actually present in the row returned by your query. A PHP array key refers to a result field, not to a page filename. If $row['id'] triggers an undefined array key warning, inspect the returned row and query fields to find the actual ID key, then use it in the link.
Rank #2
- Wrong label: confirm the result contains the company-name field you use, such as
compname. - Wrong destination: confirm the detail page path is correct and that it expects the parameter name in the URL.
- Wrong record: confirm the ID comes from the same row as the displayed company name.
Escape the value for the context where it appears
Database text printed as HTML should be escaped. htmlspecialchars() converts HTML-special characters and is suitable for most HTML-document contexts when the source and document character sets match. The example uses ENT_QUOTES and UTF-8 so quotes are escaped as well.
Values inserted into a URL component should be URL-encoded. rawurlencode() encodes a value for use in a URI component; here it encodes the row’s ID in the query parameter. Escape the link text as HTML separately, as shown in the example.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Quick Recap
Rank #4
Quick checklist
- Place the anchor inside the
<td>that displays the company name. - Build its destination from the current row’s real ID field.
- Use the same query-parameter name in the URL and on the detail page.
- Validate the received ID before looking up the record.
- Escape the company name for HTML and encode the ID for its URL component.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

