egturnkey Posted November 17, 2010 Share Posted November 17, 2010 Hello dear friends, If i've database table has named as info (id, name, number) and i wanna say select from info where name must has value not empty select * from info where name='xxxxwhatxxx' i've tired $name and $1 and 1 but all not working how to say where name must has value and not empty example if i've (id, name, number) values (1, 'manal', '4') (id, name, number) values (2, 'shimaa', '7') (id, name, number) values (3, '', '3') and i wanna say sellect from info where name has value so it shows me only data of id "1" and "2" only thank you so much it would helps me alot to improve myself Quote Link to comment https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/ Share on other sites More sharing options...
Psycho Posted November 17, 2010 Share Posted November 17, 2010 I think it depends on whether the ones you want to exclude have an empty string value or a null value - there is a diffrence. Try this: select * from info where name <> '' Edit: Actually I don't think nulls will matter since they won't be included in the result set or the excluded set since you can't compare null to a non null value. Quote Link to comment https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/#findComment-1135762 Share on other sites More sharing options...
mikosiko Posted November 17, 2010 Share Posted November 17, 2010 read: http://dev.mysql.com/doc/refman/5.0/en/problems-with-null.html Quote Link to comment https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/#findComment-1135764 Share on other sites More sharing options...
blink359 Posted November 17, 2010 Share Posted November 17, 2010 If its just blank and not null i belive $result = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_array($result)) { if($row['name'] !='') { echo 'id:'. $row['id'] .' name:'. $row['name'] .'number:'. $row['number'] .'<br>'; } } would work, Just tested it with different values in my database and it worked Quote Link to comment https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/#findComment-1135766 Share on other sites More sharing options...
egturnkey Posted November 17, 2010 Author Share Posted November 17, 2010 thank you all for informations and the null problem informations link. i've read it @blink359 thank you so much i've used your way using (name!='') and worked perfect. Quote Link to comment https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/#findComment-1135769 Share on other sites More sharing options...
Psycho Posted November 17, 2010 Share Posted November 17, 2010 @blink359's code will work, but it is not good programming. If you are not going to use the records where name!='' then don't pull them from the database. Otherwis,e you are just wasting system resources on the server. I just did a test and the solution I provided works to exclude records that have a name value of NULL or an empty string: $result = mysql_query("SELECT * FROM info"); while ($row = mysql_fetch_array($result)) { echo "id: {$row['id']}, name: {$row['name']}, number: {$row['number']}<br />\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/#findComment-1135827 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.