|
Posted by ZeldorBlat on 10/07/00 11:31
> //collect vars&values :D
>foreach ( $_REQUEST as $key => $value ) {
> $$key = $value;
>
>if ($key == "fruit_name") {
This doesn't make any sense since $_REQUEST can only have one value
with a key of "fruit_name".
> $fruit_name0 = ("fruit_name like '$value'");
>
> $sql = ("SELECT * FROM fruit_table where $fruit_name0");
I could be wrong, but I think the OP wanted the user input to come from
a well-defined list of fruits rather than use a pattern match.
I'm not sure how you have things setup for the user to choose, so let's
suppose it was a multiple-select list called "fruit." On the page that
processes the form, this will show up as $_REQUEST['fruit'] which is
itself an array (with an element for each fruit the user selected):
$_REQUEST['fruit'] = array('apple', 'pear', 'orange');
So now we need to get them into a query. With lists of items like this
I prefer to use an in-cluase, mainly because it's really easy to come
up the query:
$fruits = $_REQUEST['fruit'];
//Need to put the quotes around them
foreach($fruits as $i => $val)
$fruits[$i] = "'" . $val . "'";
$inList = implode(', ', $_REQUEST['fruit']));
//$inList is now a string that looks like: "'apple', 'pear', 'orange'"
$query = "select * from fruit_table where fruit_name in ($inList)";
Navigation:
[Reply to this message]
|