emma57573 Posted October 28, 2008 Share Posted October 28, 2008 Ive forgotton how to do this and cant find the syntax Im searching in a mysql table and I want to say if the field is blank! If you get hat I mean so: $mytable=mysql_fetch_array(mysql_query("select * from mysqltable where !field=""")); but you cant do '!' in the middle of a query for !field="" so what can you do to ask if the field is blank? Thanks Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/ Share on other sites More sharing options...
mtylerb Posted October 28, 2008 Share Posted October 28, 2008 $mytable=mysql_fetch_array(mysql_query("SELECT * FROM mysqltable WHERE field != ''; ")); How's that? Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676481 Share on other sites More sharing options...
trq Posted October 28, 2008 Share Posted October 28, 2008 SELECT * FROM mysqltable WHERE field = '' By the way, connecting multiple mysql_* functions like that is very poor coding. You have no chance of handling any errors. Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676483 Share on other sites More sharing options...
bobbinsbro Posted October 28, 2008 Share Posted October 28, 2008 IIRC, SQL syntax uses the NOT keyword instead of the ! operator. Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676485 Share on other sites More sharing options...
emma57573 Posted October 28, 2008 Author Share Posted October 28, 2008 Still nothing Ive been playing with 'IS NOT EMPTY STRING' but with no luck Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676516 Share on other sites More sharing options...
MadTechie Posted October 28, 2008 Share Posted October 28, 2008 test <?php //test #1 $query = "SELECT * FROM mysqltable WHERE NOT ISNULL(field)"; //test #2 #$query = 'SELECT * FROM mysqltable WHERE field !="" '; $result = mysql_query($query) or die("error in: '$query'<br>".mysql_error()); $myrow=mysql_fetch_array($result); echo "<pre>"; print_r($myrow); ?> Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676523 Share on other sites More sharing options...
solon Posted October 28, 2008 Share Posted October 28, 2008 Try $qry = mysql_query("SELECT * FROM `mysqltable` WHERE `field`= ''"); $mytable=mysql_fetch_array($qry); Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676524 Share on other sites More sharing options...
Maq Posted October 28, 2008 Share Posted October 28, 2008 Im searching in a mysql table and I want to say if the field is blank! What do you mean, "say if the field is blank!"? Looks to me you want to get all records that aren't blank... If that's the case then you should use MadTechie's solution and use the NOT ISNULL(). Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676540 Share on other sites More sharing options...
trq Posted October 28, 2008 Share Posted October 28, 2008 Still nothing Ive been playing with 'IS NOT EMPTY STRING' but with no luck Your question is unclear. First you say you want to select a record where the field IS empty, now your saying where its NOT empty. Which is it? IIRC, SQL syntax uses the NOT keyword instead of the ! operator. The ! operator is perfectly valid, at least in MySql. Link to comment https://forums.phpfreaks.com/topic/130415-quick-syntax-question/#findComment-676542 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.