PHP IF STATEMENT NOT WORKING

HI

I think i must be going mad but i cant see why the below code wont work!!!

ANy suggestions

--s--
<?php
 
// THIS WONT WORK
if($type != '' || $type != 'a')
   $search_url .= ',type%3D'.$type;
 
// THIS WONT WORK
if(!empty($type) || $type != 'a')
   $search_url .= ',type%3D'.$type;
 
// THIS WORK AROUND DOES
if($type == '' || $type == 'a'){}else $search_url .= ',type%3D'.$type;

Open in new window

LVL 1
socrossAsked:
Who is Participating?
 
steelseth12Connect With a Mentor Commented:
You need to use && to get the results you want .

if($type != '' && $type != 'a')
   $search_url .= ',type%3D'.$type;
0
 
nplibCommented:
if(($type != '') || ($type != 'a')) {
   $search_url .= ',type%3D'.$type;
}
0
 
socrossAuthor Commented:
Already Tried that and its not working, this is driving me crazy!!

--s--

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nplibCommented:
where are you getting the value for $type,

I don't see it declared anywhere.
0
 
steelseth12Commented:
// THIS WONT WORK
if($type != '' && $type != 'a')
   $search_url .= ',type%3D'.$type;
 
// THIS WONT WORK
if(!empty($type) && $type != 'a')
   $search_url .= ',type%3D'.$type;
0
 
socrossAuthor Commented:
nplib

$type is a posted varible.

steelseth12

Ok so if those wont work, what will and why dont they work??

--s--
0
 
steelseth12Commented:
&& (AND) will work the ones i show above .... you had || (OR)
0
 
socrossAuthor Commented:
As the value for type comes from a drop down. it will never be && i need it to work with ||

Why would it not?

--s--
0
 
steelseth12Commented:
Its a double negative you have to use && ... it just will not work will || ... why do you have to use || ??????
0
 
socrossAuthor Commented:
well i need to say

if (type does not equal '' or type does not equal 'a') add value to the varible
0
 
steelseth12Commented:
if thats what you need to say then your if statement is returning the correct result.

If type does not equal to '' OR type not equal to a then it means that in the first part it can be any value except '' (INCLUDING a) the second part any value except a (including '') .... so if its either of the 2 then you are getting the correct result.
0
 
socrossAuthor Commented:
Right ok, so under what circustances would it run the script contained in the if statment.

I only need it to run the script if type does not equal empty or not equal a

Could you write the script that will work for this?

--s--
0
 
nplibCommented:
Man I go have lunch, and the problem gets solved.
Oh Well.
0
 
socrossAuthor Commented:
just driven home and it all seemed to make sense, its amazing when you look at something so simple you can miss the really obvious stuff!!!

Thanks for persevering with me.

Thanks

--s--
0
 
socrossAuthor Commented:
Mind caught up in the end
0
 
steelseth12Commented:
i once try to explain it to a friend of mine that was been programming for over 10 years. After 3 hours 2 packs of cigarettes and waking up the wife we agreed not to bring it up again. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.