Re: query selection
| From: | CPT John W. Holmes | Date: | Mon, 16 Jun 2003 19:12:36 +0000 |
| Subject: | Re: query selection | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-28656@lists.php.net to get a copy of this message | ||
> the first list that is displayed has an ID for each product. But when I
> click on it, it goes to the next page but does not display the rest of the
> products that are listed in the second table.
>
> $query = "SELECT * FROM product_list WHERE productid = id";
>
> Id being the description ID that came off the first page.
Well, 'id' should at least be a variable, right? I assume your links look
something like this:
http://www.yourdomain.com/page.php?id=X
where X is the 'id' number you want to pass to the above select statement.
If so, then you'd use:
$query = "SELECT * FROM product_list WHERE productid = {$_GET['id']}";
or
$query = "SELECT * FROM product_list WHERE productid = " . $_GET['id'];
where $_GET['id'] is a variable containing the value passed in the URL. Make
sure you properly validate $_GET['id'] to make sure it's a valid ID (or at
least an integer) before you stick it in your SQL statement, also.
$id = (int)$_GET['id'];
$query = "SELECT * FROM product_list WHERE productid = $id";
---John Holmes...