You are here: Re: [PHP] Using GET to build multiple sql queries « PHP « IT news, forums, messages
Re: [PHP] Using GET to build multiple sql queries

Posted by Jack Jackson on 06/02/05 23:15

SORRY - one small correction below:

<SNIP>

If that were instead an $s then I would do:

<?php //IF there is a valid query by subject, use $s to build the SQL
$fields = "SELECT art.*,publisher.*,subject.*";
$from = "FROM art,subject
LEFT JOIN publisher
ON publisher.publisher_id=art.publisher_id";
$where = "WHERE publisher.publisher_id=art.publisher_id AND
art.subject_id = '$s' AND
art.subject_id=subject.subject_id";
?>

</SNIP>
I had accidentally put a number 1 in place of the $s in the above
example. Apologies for the extra mail and thanks in advance.




Greg Donald wrote:
> 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 );
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация