Right, bare with me pls, i need to query the db and return a part number and model, but the thing is these results need to link a page where they are displayed fully

heres an example

if u type in the bottom box W02-358 in returns 3 results which are in turn linked to a page where they display fully.

Im not asking for the code or anything doing for me but suggestions of the best way to go about this

Dani AI

Generated

As pointed out, the cleanest pattern is to make each search result a link to a dedicated details page that identifies which record to load. For this usually means including a stable identifier in the URL (an integer id or a UUID) and optionally a human-friendly slug made from the part number/model for usability and SEO. The details page should validate that identifier, fetch the record with a safe database query, and return a proper 404 or redirect if nothing matches.

A minimal server-side workflow (safe, simple) looks like this:

// $pdo is a PDO instance
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if (!$id) { http_response_code(404); exit; }

$stmt = $pdo->prepare('SELECT * FROM products WHERE id = ? LIMIT 1');
$stmt->execute([$id]);
$product = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$product) { http_response_code(404); exit; }

// optional: check slug and redirect to canonical URL if it differs

Use prepared statements (PDO) to avoid SQL injection and validate all input early. See PHP prepared statements for examples and OWASP guidance on injection attacks for why this matters (PDO prepared statements, OWASP: SQL Injection).

Troubleshooting/performance tips: ensure the id column is indexed, paginate search results, normalize search input (trim/case), consider full-text or n-gram indexes for part numbers, and use caching or HTTP cache headers for product pages. If exposing sequential IDs is a concern, use opaque tokens or slugs instead.

Recommended Answers

All 2 Replies

When you display your results, display them as a hyperlink and store the product id in the url. Then when you go to the details page, use $_GET to retrieve it.

When you display your results, display them as a hyperlink and store the product id in the url. Then when you go to the details page, use $_GET to retrieve it.

I think i understand, ill give it a try and et you know how far i get

Thanks
Dan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.