The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Put a normal HTML <a> element inside each table cell, use the current row’s record ID to build its href, and print the company name as the link text. The detail script must read the same query parameter, such as id.
Link a company name from the current row
PHP generates the HTML; an anchor works the same way inside a table cell as anywhere else. Keep the visible label and destination separate: the label comes from compname, while the URL contains the row’s unique identifier.
<?php
echo '<td><a href="readcompany.php?id=' .
rawurlencode((string) $row['id']) .
'">' .
htmlspecialchars($row['compname'], ENT_QUOTES, 'UTF-8') .
'</a></td>';
?>
This assumes the query result contains both id and compname, and that readcompany.php expects a parameter named id. The page filename is written directly in the URL; it is not a key in $row.
Generate the link while rendering the table
A complete loop might look like this:
<table>
<tbody>
<?php foreach ($rows as $row): ?>
<tr>
<td>
<a href="readcompany.php?id=<?= rawurlencode((string) $row['id']) ?>">
<?= htmlspecialchars($row['compname'], ENT_QUOTES, 'UTF-8') ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Use the syntax that matches your application. In either form, escape database text for HTML and encode values inserted into a URL component.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Read the ID on the detail page
The receiving script must use the same parameter name emitted by the table:
<?php
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if ($id === false || $id === null || $id < 1) {
http_response_code(400);
exit('Invalid company ID');
}
// Fetch the company whose primary key is $id, then render its details.
?>
If your identifiers are not positive integers, validate them according to the application’s actual type and allowed range instead. Missing, malformed, or unauthorized IDs should not be treated as valid records.
Rank #2
Fix undefined-index and empty-link problems
Confirm the result keys
An expression such as $row['id'] only works when the SQL result actually includes a column returned under the key id. An undefined-index warning means that key is absent or named differently. Inspect one fetched row and compare its keys with the names used in the template; alias the SQL column or change the PHP key as appropriate.
Match both parameter names
A link using readcompany.php?id=42 must be read with $_GET['id'] (or equivalent input filtering). If the table emits company_id but the detail page reads id, the detail lookup will receive nothing.
Check the generated HTML
View the page source or inspect the element in your browser. Each row should contain a complete URL, a nonempty label, and balanced opening and closing anchor tags. A missing quote or concatenation operator can make later table markup part of the link.
Quick Recap
Rank #4
Escaping rules that prevent broken markup
- Company name: pass database-derived text through
htmlspecialchars($value, ENT_QUOTES, 'UTF-8')before placing it in HTML text or an attribute. - URL value: encode a value inserted into a URL component with
rawurlencode(). For an integer ID this is harmless and keeps the boundary explicit. - Query parameter: validate it again on the detail page. Encoding protects the generated URL; it does not establish that the requested record exists or that the visitor may view it.
Common mistakes
- Using
$row['readcompany.php']: row keys are database fields, not page filenames. - Linking with the company name as the identifier when names are not guaranteed to be unique. Prefer the record’s primary key.
- Printing raw company names or IDs into HTML without context-appropriate escaping.
- Emitting one parameter name and reading another on the destination page.
- Assuming a present ID is automatically valid; handle missing, invalid, and out-of-range input explicitly.
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.




