EricOnAdventure Posted June 23, 2016 Share Posted June 23, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/301382-testing-is-a-column-in-the-database-is-set/ Share on other sites More sharing options...
EricOnAdventure Posted June 23, 2016 Author Share Posted June 23, 2016 I found an odd way to solve my issue, but I would still appreciate any solutions. What I do is : $DEGREETYPE =''; $DEGREETYPE = findit('DEGREETYPE','1moreinfo'); if ($DEGREETYPE != ''){ do this } else{ do that } Quote Link to comment https://forums.phpfreaks.com/topic/301382-testing-is-a-column-in-the-database-is-set/#findComment-1533956 Share on other sites More sharing options...
Muddy_Funster Posted June 23, 2016 Share Posted June 23, 2016 let's see the findit function Quote Link to comment https://forums.phpfreaks.com/topic/301382-testing-is-a-column-in-the-database-is-set/#findComment-1533959 Share on other sites More sharing options...
Solution Psycho Posted June 23, 2016 Solution Share Posted June 23, 2016 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 } Quote Link to comment https://forums.phpfreaks.com/topic/301382-testing-is-a-column-in-the-database-is-set/#findComment-1533960 Share on other sites More sharing options...
EricOnAdventure Posted June 24, 2016 Author Share Posted June 24, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/301382-testing-is-a-column-in-the-database-is-set/#findComment-1533988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.