/    Sign up×
Community /Pin to ProfileBookmark

Difficulty recognizing null values in database

I’m trying to show values from a database using mssql, if there is a value in the shipp_attn field, I will display that, if that is missing, I will display the shipname, and if that is missing I will display the order number which I know is there.

This is the code I have for it:
if($ShipAttn != “”){
echo”<a href=”./PendingOrders.php?OID=$OrderID”>$ShipAttn (Order Number: $OrderID)</a><br>”;
}elseif($ShipName != “”){
echo”<a href=”./PendingOrders.php?OID=$OrderID”>$ShipName (Order Number: $OrderID)</a><br>”;
}else{
echo”<a href=”./PendingOrders.php?OID=$OrderID”>(Order Number: $OrderID)</a><br>”;
}

This code works fine so long as there is a <null> in the shipp_attn($ShipAttn) field, however some of the missing values simply have nothing in the field instead of <null> and my code will not recognize that as “”, null, or not being set, as I have tried all seperately and together. When one of these fields comes up it will not jump to the elseif($ShipName != “”) part and it will display..nothing. I have no idea why it is doing this, would anyone be able to lend a hand?

I added those (Order Number: $OrderID)’s in as a temporary solution, but I would like to have this work as I had planned out.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdJun 15.2006 — Try using the strval() function:

if (strval($ShipAttn) != ""

Try also echoing out the serialized value of your variable:

echo serialize($ShipAttn)

To see what it is actually being set as
Copy linkTweet thisAlerts:
@EbolaauthorJun 15.2006 — Tried it, same result.

s:1:" " is what it's being serialized as, I'll try adding (|| $ShipAttn == " ") into there and see if it catches it.
Copy linkTweet thisAlerts:
@abou_hmedJun 15.2006 — just try this condition

f($ShipAttn){
Copy linkTweet thisAlerts:
@Frankie_CWRUJun 15.2006 — Is there any consistency to what value should be stored in $ShipAttn when it is legitimately set? If so you could check it against a regular expression instead of against null.

Otherwise (a ****ty workaround, but it might work):

Always display $ShipAttn, if it is set, then you will display $ShipAttn as well as $OrderID and if it is not set then it will only display $OrderID
Copy linkTweet thisAlerts:
@EbolaauthorJun 15.2006 — It worked after I changed the code to this:

if(strval(($ShipAttn) != "") && ($ShipAttn != " ")){

//blah blah

}

Although the empty variable wasn't actually displaying a space at all (I made sure of this), that code is catching it, thanks alot Webnerd.
Copy linkTweet thisAlerts:
@NogDogJun 15.2006 — You could try using trim():
[code=php]
if(trim($ShipAttn) != "")
{
// blah blah
}
[/code]
×

Success!

Help @Ebola spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...