Jump to content

testing is a column in the database is set


EricOnAdventure
 Share

Go to solution Solved by Psycho,

Recommended Posts

Hey guys, I have a working mysqli function that pulls info from the database

so this works perfectly :

$DEGREETYPE = findit('DEGREETYPE','moreinfo');
echo $DEGREETYPE;

However I would like to see if degree type is set, and since I cannot use isset with a function I tried this

if(findit('DEGREETYPE','moreinfo')!=''){$DEGREETYPE = findit('DEGREETYPE','moreinfo');}else {$DEGREETYPE='nooo';}
echo $DEGREETYPE;

sadly this didn't work

any ideas?

Link to comment
Share on other sites

  • Solution

First, you need to decide what "is set" in the database means. Does it mean the field is NULL, an empty string, or what? Can the values you are pulling be FALSE? If not, have your function return the Boolean FALSE when the value is not set. Then you can do something like this:

 

 

if(findit('DEGREETYPE','1moreinfo') !== false){
    //Do this
} else {
    //Do that
}

 

Are you actually using the value from the DB or just checking if it "exists" (whatever that means). If you are just checking if the value exists, then have the function return TRUE/FALSE. Also, the !== is only needed if any legitimate values would be interpreted as false. For example, a value of 0 or an empty string would be interpreted as false, do the double equal sign is needed to do a strict comparison. If you won't have any such values in the return data, you could simplify it even more such as this:

 

 

if(findit('DEGREETYPE','1moreinfo')){
    //Do this
} else {
    //Do that
}
Link to comment
Share on other sites

 

First, you need to decide what "is set" in the database means. Does it mean the field is NULL, an empty string, or what? Can the values you are pulling be FALSE? If not, have your function return the Boolean FALSE when the value is not set. Then you can do something like this:

if(findit('DEGREETYPE','1moreinfo') !== false){
    //Do this
} else {
    //Do that
}

Are you actually using the value from the DB or just checking if it "exists" (whatever that means). If you are just checking if the value exists, then have the function return TRUE/FALSE. Also, the !== is only needed if any legitimate values would be interpreted as false. For example, a value of 0 or an empty string would be interpreted as false, do the double equal sign is needed to do a strict comparison. If you won't have any such values in the return data, you could simplify it even more such as this:

if(findit('DEGREETYPE','1moreinfo')){
    //Do this
} else {
    //Do that
}

 

I see, thanks for the code, I didn't know it would be so easy. And yes, for the most part I just need to see if they are set because I'm using many as booleans

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.