I am having a user enter a phrase into a textbox, and then I need to
seperate the words he has typed into variables so I can use each one
in an sql statement. I know I will use the explode() function to do this,
but how will I know how many variables I've created. For instance, if a
user types in 3 words seperated by spaces, how will I know i'll have
var[0] through var[2]? how about when they type in 2 words or 4 words?
How will I know how many words they have typed in? The only way I can
think of to do this is:
// $var is the input after being ran through explode()
$i = 0;
while ($var[$i])
{
$i++;
}
I will then take the data they enter and create the sql statement:
$j = 0;
$sql = "select subject from subfile where";
while ($j <= $i)
{
$j++;
$sql .= "suject matches '*$var[$j]*'";
if ( $j != $i)
{
$sql .= " and ";
}
}
but I think there has to be a better way to do this. any ideas?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php