Re: Using GET to build multiple sql queries
| From: | Greg Donald | Date: | Thu, 02 Jun 2005 17:28:02 +0000 |
| Subject: | Re: Using GET to build multiple sql queries | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-216251@lists.php.net to get a copy of this message | ||
On 6/2/05, Jack Jackson <jackson.linux@gmail.com> wrote:
> I'd love some help with
> http://hashphp.org/pastebin?pid=3443 if anyone
> can...
>
> Basically I want to make it so that, if the get in the url specifies no
> query or a query to a nonexistent row, send to vanilla index. If url
> specifies c= then set $c=c and use the number to build the mysql query;
> same for p= and s= - if they're valid build the query, if not kick em out.
>
> Can anyone offer any help?
I'd iterate over the $_GET array to build the query elements. Then
implode those elements.
$array = array();
while( list( $k, $v ) = each( $_GET ) )
{
if( $k == 'somekeynotindb' )
{
continue;
}
$array[] = $k . "='" . $v . "'";
}
if( $array )
{
$and = implode( ', ', $array );
}
$sql = "
SELECT *
FROM table
WHERE 1
$and
";
$query = mysql_query( $sql );
--
Greg Donald
Zend Certified Engineer
http://destiney.com/