Moron Posted August 14, 2007 Share Posted August 14, 2007 If I put this in my query, (using myself as the input) : WHERE M2.[MSSNO] = '".$_SESSION['password']."' AND LH.[Lyr] = '$last' AND LH.[Lmo] <= '07' (Month is less than July - '07') ...everything is fine. It's because I've taken leave this year, but before July. If I put this: WHERE M2.[MSSNO] = '".$_SESSION['password']."' AND LH.[Lyr] = '$last' AND LH.[Lmo] >= '07' (Month is greater than July - '07') ...it crashes and burns. I haven't taken any leave since before July. So what's the proper way to write this syntax? Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/ Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 Can you post the sql error that is returning? Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323828 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 Can you post the sql error that is returning? It isn't returning a sql error. It just does what I have listed under the "die" statement. I basically want it to remain blank if no records meet the criteria. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323838 Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 Where is your die statement? is it trying a sql query? More code would be helpful because it doesn't look like there is any error in your sql that you have shown. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323844 Share on other sites More sharing options...
Barand Posted August 14, 2007 Share Posted August 14, 2007 Can you post the sql error that is returning? It isn't returning a sql error. It just does what I have listed under the "die" statement. I basically want it to remain blank if no records meet the criteria. Get your die statement to give you some useful info, like the error message Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323859 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 Get your die statement to give you some useful info, like the error message But I already know what the "error" is. There are no records that meet my "WHERE" condition. But instead of it "dying," I want it to either echo blank or say "You've taken no leave this fiscal year" or something to that effect. See what I mean? Sorry about the misunderstanding. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323886 Share on other sites More sharing options...
Barand Posted August 14, 2007 Share Posted August 14, 2007 if you have $result - mysql_query("sql statement") or die ("Some message") then it will only execute the die() bit if there is an error. Finding no records is NOT an error. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323890 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 if you have $result - mysql_query("sql statement") or die ("Some message") then it will only execute the die() bit if there is an error. Finding no records is NOT an error. Yes. That's exactly what it's doing. There's no sql error at all. It just goes to the "die" statement (which, of course, makes perfect sense ), but I guess what I'm really asking is....I don't want it to die; I want it to echo something if no records match. See what I mean? EDIT: Like I mentioned in the first post, If I use <= '07' ... it works because because I've taken leave before July of this year. If I change the "less than" to a "greater than".... >= '07' ....it proceeds to the "die" statement. This is as it should be, but rather than dying, I want it to echo that no leave has been taken this fiscal year. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323893 Share on other sites More sharing options...
Barand Posted August 14, 2007 Share Posted August 14, 2007 I appreciate English may not be your first language so I'm typing this slowly. It-will-only-go-to-the-die-statement-if-there-is-an-error. If-it-finds-no-records-that-is-NOT-AN-ERROR. So-it-is-NOT-going-to-the-die-statement-because-it-has-not-found-any-records. Unless, of course, there is something weird about the way you call your die() statement (which we haven't seen) Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323913 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 I appreciate English may not be your first language so I'm typing this slowly. It-will-only-go-to-the-die-statement-if-there-is-an-error. If-it-finds-no-records-that-is-NOT-AN-ERROR. So-it-is-NOT-going-to-the-die-statement-because-it-has-not-found-any-records. Unless, of course, there is something weird about the way you call your die() statement (which we haven't seen) Excuse my lack of experience with all this, okay? Why would the exact same query throw an error by just changing the "less than" to a "greater than?" Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323918 Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 If no records match, it should return an empty query, not die. The fact that it is dying means there must be an error in the sql. change your die message to: die(mysql_error()); let us know what it prints out. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323921 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 If no records match, it should return an empty query, not die. The fact that it is dying means there must be an error in the sql. change your die message to: die(mysql_error()); let us know what it prints out. Thanks. I'm using MS SQL, not MySQL. I changed your statement to die(mssql_error()); It gives me "Fatal error: Call to undefined function mssql_error() in <path>. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323926 Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 Ok use mssql_get_last_message() Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323929 Share on other sites More sharing options...
Barand Posted August 14, 2007 Share Posted August 14, 2007 Can you give us the whole statement where you call die() Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323934 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 Ok use mssql_get_last_message() This works but comes up totally blank. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323935 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 Can you give us the whole statement where you call die() Sure. It is: $RESULT=mssql_fetch_assoc($RESULTDS) or die("<CENTER><img src=\"http://orserva/images/invalidnumber.gif\"></CENTER><BR><CENTER><table width=60 border=0><tr><td><font size=\"3\" color=\"#000000\" face=\"arial\">Need help? Here is an example entry:</font></td></tr><tr><td align=center><img src=\"http://orserva/images/leaveexample.gif\"></td></tr><tr><td><font size=\"3\" color=\"#000000\" face=\"arial\">Enter your EMPNO<BR>Enter your password (Social Security Number)<BR>Click Submit<BR><BR>If you're still having difficulty, click here to </font><font size=\"3\" color=\"#ff0000\" face=\"arial\"><BR><a href=\"mailto:HelpDesk@organization.org? subject=Problem with the Leave Management System\"><b>E-mail the HelpDesk</b></a></font></td></tr></table></CENTER>"); Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323937 Share on other sites More sharing options...
Barand Posted August 14, 2007 Share Posted August 14, 2007 try changing die to echo Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323942 Share on other sites More sharing options...
chronister Posted August 14, 2007 Share Posted August 14, 2007 $RESULT=mssql_fetch_assoc($RESULTDS) or die("<CENTER><img That is why your script is dying, you are telling it to do something unless it don't find records, then die REMOVE THAT or die and all will be well with the universe, you only want the or die clause on the query itself, not when your retrieving data Unless I am missing something, then this should fix it. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323946 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 try changing die to echo That's what I want to do, but it gives me the "unexpected t_echo" error. Removing the "die" statement works, but I really want to use echo. Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323956 Share on other sites More sharing options...
Moron Posted August 14, 2007 Author Share Posted August 14, 2007 $RESULT=mssql_fetch_assoc($RESULTDS) or die("<CENTER><img That is why your script is dying, you are telling it to do something unless it don't find records, then die REMOVE THAT or die and all will be well with the universe, you only want the or die clause on the query itself, not when your retrieving data Unless I am missing something, then this should fix it. I see. Yeah, that makes sense. I guess I didn't think of it as an "error" because I knew that no records would match (using my info as the input). So how do I use "or echo" in place of "or die?" Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323964 Share on other sites More sharing options...
chronister Posted August 14, 2007 Share Posted August 14, 2007 Set up an if statement e.g. I don't know offhand the equivalent for mysql_num_rows, so you'll have to do a bit of research. if(mysql_num_rows($RESULTDS) > 0) { 'ECHO THE RESULTS HERE'; } else { echo 'No Results Found'; } It does not look like your running this through a loop, which means that you'll only get the last result Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-323969 Share on other sites More sharing options...
Moron Posted August 15, 2007 Author Share Posted August 15, 2007 Set up an if statement e.g. I don't know offhand the equivalent for mysql_num_rows, so you'll have to do a bit of research. if(mysql_num_rows($RESULTDS) > 0) { 'ECHO THE RESULTS HERE'; } else { echo 'No Results Found'; } It does not look like your running this through a loop, which means that you'll only get the last result Perfect. I'll try this tomorrow. Thanks, everyone! Quote Link to comment https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/#findComment-324223 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.