SEVIZ Posted April 19, 2009 Share Posted April 19, 2009 With this code: select 'sup' from sprint GROUP BY 'sup'"; How do I edit it so that if 'sup' = NULL to ignore it? Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/ Share on other sites More sharing options...
Philip Posted April 19, 2009 Share Posted April 19, 2009 select `sup` from `sprint` WHERE `sup` IS NOT NULL GROUP BY 'sup' Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813501 Share on other sites More sharing options...
SEVIZ Posted April 19, 2009 Author Share Posted April 19, 2009 For some reason the null option still shows. Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813504 Share on other sites More sharing options...
Philip Posted April 19, 2009 Share Posted April 19, 2009 Opps, it should have thrown an error for it anyways. (note the different tick marks) SELECT `sup` FROM `sprint` WHERE `sup` IS NOT NULL GROUP BY `sup` Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813506 Share on other sites More sharing options...
SEVIZ Posted April 19, 2009 Author Share Posted April 19, 2009 This should be working. Its something I actually had tried before but the option still shows. Here is my full code in case its needed for something else I am missing. <?php $q = "SELECT `sup` FROM `sprint` WHERE `sup` IS NOT NULL GROUP BY `sup`"; $ret = mysql_query($q); while ($row = mysql_fetch_assoc($ret)) { $email_sec = $row['sup']; print "<option value=\"$email_sec\">Team $email_sec</option>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813510 Share on other sites More sharing options...
Philip Posted April 19, 2009 Share Posted April 19, 2009 add or die(mysql_error()); $ret = mysql_query($q) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813512 Share on other sites More sharing options...
SEVIZ Posted April 19, 2009 Author Share Posted April 19, 2009 Did that now and no error shows and the item remains. I am in the twilight zone I think. This is so simple but I am missing something. Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813514 Share on other sites More sharing options...
Philip Posted April 19, 2009 Share Posted April 19, 2009 Yeah, and I'm blind too haha. Running it in something like PhpMyAdmin returns nothing as well? Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813517 Share on other sites More sharing options...
SEVIZ Posted April 19, 2009 Author Share Posted April 19, 2009 Just ran it in phpmyadmin and again the empty option shows. Somehow even though its empty, its not showing as NULL? Is that the only possibility left? Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813518 Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 how did those rows in `sup` get to be null in the first place? do you have it set as the default and when you insert a new row, leave that column blank? when you insert a new row, are you doing null or 'null' if you are putting something? point I'm trying to make is, maybe it's not really NULL but is storing a string of value "NULL" or an empty string "" (which is not the same as null), due to however you have your db or code setup. Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813521 Share on other sites More sharing options...
SEVIZ Posted April 19, 2009 Author Share Posted April 19, 2009 how did those rows in `sup` get to be null in the first place? do you have it set as the default and when you insert a new row, leave that column blank? when you insert a new row, are you doing null or 'null' if you are putting something? There are only two items that are empty in this spot. I imported all the data from an excel sheet originally. In phpmyadmin this is set as "not null" with no default set if that matters. Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813524 Share on other sites More sharing options...
SEVIZ Posted April 19, 2009 Author Share Posted April 19, 2009 Figured it out. I am an idiot. I did not have these items set as NULL. As you said, they were just empty. I fixed it. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813526 Share on other sites More sharing options...
.josh Posted April 19, 2009 Share Posted April 19, 2009 okay well if you have it set to be "not null" then they are not null, and that's why your query isn't working the way you want. You need to change the condition to something else like ..where `sup` != '' or ..where length(`sup`) > 0 edit: ah okay cool. Quote Link to comment https://forums.phpfreaks.com/topic/154706-solved-if-row-null-in-query-ignore/#findComment-813527 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.