IBMKenobi
asked on
If statement is producing odd result (PHP)
I have a search script which works very well but one choice in the menu produces an odd result.
The site is fully working at http://www.glutenfreeirela nd.net/whe retoeat.ph p
These example works:
Choose Location: Armagh
Choose Accommodation: Hotel
Leave the rest as default settings.
The results are perfectly laid out.
Do the same search using Cork City as the location, Hotel accommodation plus defaults.
Again the results work perfectly.
You can also choose any combination of counties and cities and get perfect results, with the exception of Belfast City.
Choose Belfast City as the location and a blank line is inserted in the result.
Choose Belfast City and any other county (Carlow also has a hotel for example) and the County Carlow results show County Antrim.
This is the code for displaying the search results:
The site is fully working at http://www.glutenfreeirela
These example works:
Choose Location: Armagh
Choose Accommodation: Hotel
Leave the rest as default settings.
The results are perfectly laid out.
Do the same search using Cork City as the location, Hotel accommodation plus defaults.
Again the results work perfectly.
You can also choose any combination of counties and cities and get perfect results, with the exception of Belfast City.
Choose Belfast City as the location and a blank line is inserted in the result.
Choose Belfast City and any other county (Carlow also has a hotel for example) and the County Carlow results show County Antrim.
This is the code for displaying the search results:
while ($searchresults = mysql_fetch_array($sql_result)) {
$venueID = $searchresults['VID'];
$name = $searchresults['name'];
$address1 = $searchresults['address1'];
if ($address2 = $searchresults['address2']) {
$address2 = $searchresults['address2'].'<br />';
}
$vcounty = $searchresults['county'];
if ($vcounty == 'Belfast City') {
$ccounty = 'County Antrim';
} elseif ($vcounty == 'Dublin City') {
$ccounty = 'County Dublin';
} elseif ($vcounty == 'Cork City') {
$ccounty = 'County Cork';
}
if (isset ($ccounty)) {
$vcounty = $vcounty.'<br />'.$ccounty.'<br />';
} else {
$vcounty = 'County '.$vcounty.'<br />';
}
The cities are listed in addition to the counties for a more precise search and in some cases the city name doesn't match the county name, hence this piece of code to display the City Name and the County Name. The venues in the database are assigned to a single location only, e.g. Benedicts (hotel) is matched in the database with Belfast City, NOT county antrim.
Just looking at the Belfast results - my cousin had a "do" in the Ten Square Hotel a couple of years ago. Good ol' EE - the memories coming flooding back.....
:-)
:-)
ASKER
When I enter in == I get:
Undefined variable: address2
Ten Square is a very nice hotel, we're hosting our official website launch there next week (assuming it's all working!) :D
Undefined variable: address2
Ten Square is a very nice hotel, we're hosting our official website launch there next week (assuming it's all working!) :D
I had assumed that $address was defined elsewhere outside the code fragment above. Try this code
$address2 = "";
if ( trim( $searchresults['address2'] ) != "" ) {
$address2 = trim( $searchresults['address2'] ) .'<br />';
}
ASKER
That does away with the blank line nicely.
When choosing Belfast City and any other county the venues in a the county are still showing up as County Antrim and have a double county listing for their real county.
For example, Belfast City and Carlow + Hotel
When choosing Belfast City and any other county the venues in a the county are still showing up as County Antrim and have a double county listing for their real county.
For example, Belfast City and Carlow + Hotel
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You're a star, that was the last bug in a big rebuild :D
Thanks very much indeed!
Thanks very much indeed!
ASKER
Excellent, fast and concise clear answers.
You're welcome.
Good luck with your launch party - remember to test your site in as many browsers as possible so look at http://browsershots.org - it's free and well worth the investment of an hour's time.
Good luck with your launch party - remember to test your site in as many browsers as possible so look at http://browsershots.org - it's free and well worth the investment of an hour's time.
if ($address2 = $searchresults['address2']
should be == not =