Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/64903-query-crashes-if-no-data-meets-criteria/
Share on other sites

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

 

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.

 

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.

 

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)

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?"

 

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>.

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>");

$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.

$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?"

 

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

 

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!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.