Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

If statement is producing odd result (PHP)

Posted on 2011-02-26
9
Medium Priority
?
245 Views
Last Modified: 2012-06-21
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.glutenfreeireland.net/wheretoeat.php

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 />';
		}

Open in new window

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.
0
Comment
Question by:IBMKenobi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 34986758
Looks like a dodgy IF

if ($address2 = $searchresults['address2']) {

should be == not =
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 34986762
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.....

:-)
0
 
LVL 4

Author Comment

by:IBMKenobi
ID: 34986854
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 34986883
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 />';
	}

Open in new window

0
 
LVL 4

Author Comment

by:IBMKenobi
ID: 34986906
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

0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 total points
ID: 34986926
I think it is the same problem. You swap around between vCounty and cCounty and there is no re-initialisation of cCounty so any old values stay in place. Look at this code (I have put the changes in italics

     $vcounty = $searchresults['county'];
     $ccounty = "";


     if ($vcounty == 'Belfast City') {
          $ccounty = 'County Antrim';
     } else
          if ($vcounty == 'Dublin City') {
               $ccounty = 'County Dublin';
          } else
               if ($vcounty == 'Cork City') {
                    $ccounty = 'County Cork';
               }

     if ( $ccounty != "" )
          $vcounty = $vcounty.'<br />'.$ccounty.'<br />';
     else
          $vcounty = 'County '.$vcounty.'<br />';
     

0
 
LVL 4

Author Comment

by:IBMKenobi
ID: 34986936
You're a star, that was the last bug in a big rebuild :D
Thanks very much indeed!
0
 
LVL 4

Author Closing Comment

by:IBMKenobi
ID: 34986938
Excellent, fast and concise clear answers.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 34986956
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.

0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question