![]() |
Error in strpos for form
I'm coding the locations for groups, and the user can search based on the location to find the nearest group to them. The fields are: country, state, city, neighborhood. Let's say there are ten groups in the USA -- I don't want it to list the option USA ten times. I added in a strpos so that it will only list them once, but I'm getting an error.
Here's the php code: Code:
<?phpWarning: strpos(): Empty delimiter in sidebar.php on line 66 Warning: strpos(): Empty delimiter in sidebar.php on line 70 Warning: strpos(): Empty delimiter in sidebar.php on line 73 Warning: strpos(): Empty delimiter in sidebar.php on line 76 Underneath the error it has a nice form with the correct fields: country, state, city, neighborhood. It's just listing the same countries multiple times. |
Has nothing to do with MySQL. Try posting in the PHP forum.
However... I don't use PHP, but I can read documentation. http://www.php.net/manual/en/function.strpos.php Looks to me like you have the arguments to strpos( ) *BACKWARDS*. The thing to search *IN* is supposed to be first. |
OH! THIS IS FUNNY!
LOOK at that code: Code:
echo $country_options .= "<option value='" . $get_row['country'] . "'>" . $get_row['country'] . "</option>";}But what you are echoing is the FULL SET OF OPTIONS in $xxx_options! Because the .= operator returns the CONCATENATED result, not just the part *AFTER* the operator. You need to write something like this, instead: Code:
$val = $get_row["country"]; // not needed, but enhances performance |
Again, I don't use PHP, but I think you could write that a bit more compactly thus:
Code:
strpos($country_options, ( $val = $get_row["contry"] ) ) === false ) |
PHP does treat " and ' differently as well - if you wrap the text in " then it gets parsed for all sorts of escape characters and also for variable references whereas text wrapped in ' only gets parsed for \' escapes. So that's another reason to switch the quotes around.
|
| All times are GMT +1. The time now is 10:58 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.