|
Posted by Koncept on 10/21/06 17:00
In article <1161429049.560461.21980@i42g2000cwa.googlegroups.com>,
kenoli <kenoli@igc.org> wrote:
> As usual, a thoughtful reply. What I think is being done here, however
> is that you are getting a list of keywords associated with a person.
> What I want to do, however, is rhe opposite. People will select a
> group of keywords using, say, checkboxes identified with keywords from
> a lookup table and on submit I will want to return data for all the
> persons associates with any selected keyword. Something that does
> something like:
>
> SELECT * FROM persons WHERE keyword=keyword1 OR keyword=keyword 2 OR
> keyword=keyword3 etc.
>
> I know this isn't a correct query, but it illustrates conceptually what
> I will want to do.
>
> --Kenoli
Ahhh. Gotcha. How's something like this?
<?php $r = range(1,10) ?>
<form action="<?=basename($_SERVER['PHP_SELF'])?>" method="post">
<?php foreach($r as $i): ?>
<input type="checkbox" name="keywords[kw<?=$i?>]" value="on"
id="kw<?=$i?>" />Keyword <?=$i?><br />
<?php endforeach ?>
<input type="submit" value="Submit" />
</form>
<?php
// What the form got
printf("<pre>%s</pre>",htmlentities(print_r($_POST,true)));
?>
<code>
<?php
if($_POST['keywords']):
// dump mySQL statement
$sql = "SELECT * FROM persons WHERE";
// Obviously, this is ripe for SQL poisoning right now, but just to
offer a solution.
// Make sure to properly prepare and check your values
echo $sql ." keyword='".join("' or keyword='",
array_keys($_POST['keywords']))."';";
endif;
?>
</code>
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Navigation:
[Reply to this message]
|