Ask a Question related to PHP Development, Design and Development.
-
Lucas Lain #1
Re: [PHP] Bizarre SQl, if issue....
Did you try to print the content of the variable?
What does it contain?
On Tue, 29 Jul 2003 13:29:10 -0400
"Mike At Spy" <spycobalt@spyproductions.com> wrote:
>
> Hey, I've got a weird issue. I have some code, an MySQL statement, that
> returns an empty set, like this:
>
> $person = mysql_query("Some Statement Here");
>
> So, then I have an if/else statement:
>
> if (!$person || $person == 0 || $person == '' || $person == '0') { $result =
> 1; }
> else { $result = 4; }
>
> If the SQL statement returns an empty set, shouldn't $result be equal to 1?
> Instead, I'm getting $result = 4.
>
> Hence all of the 'OR' conditions. I would have have thought !$person would
> be enough.
>
> Thanks for any input! :)
>
> -Mike
>
>
>
>
> --
> PHP General Mailing List ([url]http://www.php.net/[/url])
> To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
>
>
--
Lucas Lain
[email]lainl@aconectarse.com[/email]
# /Scripting/Manager (??) && /Obscure/Commander
Lucas Lain Guest
-
Fonts are there, then they're not. Bizarre.
I am using InDesign CS on a pc. I use a limited number of fonts to layout our monthly newsletter. I installed the fonts I needed and they were... -
5.80, OS X, bizarre FTP weirdness
I am running Mac OS X 10.2.7 and recently upgraded from 5.6.1 to 5.8.0 following the guidance at... -
Bizarre SQl, if issue....
Hey, I've got a weird issue. I have some code, an MySQL statement, that returns an empty set, like this: $person = mysql_query("Some Statement... -
Bizarre HD Problem
OS: Win98/Mandrake 9.1 I just installed a new 80GB Maxtor HD (6Y080L0) and, while my BIOS sees it and it shows up in dmesg as 'hdd', a) It... -
Bizarre IE6 CSS error
Hi all, I have the weirdest thing going on... it's hard even to describe, but bascically, IE6 seems to interpret differently the margins/padding... -
Jay Blanchard #2
RE: [PHP] Bizarre SQl, if issue....
[snip]
$person = mysql_query("Some Statement Here");
if (!$person || $person == 0 || $person == '' || $person == '0') {
$result =
1; }
else { $result = 4; }
If the SQL statement returns an empty set, shouldn't $result be equal to
1?
Instead, I'm getting $result = 4.
[/snip]
Actually I think we need to see the query == "Some Statement Here".
$person in this case is either TRUE or FALSE
Jay Blanchard Guest
-
Mike At Spy #3
RE: [PHP] Bizarre SQl, if issue....
Here's the SQL - I tested it via command line and it comes back empty set.
SELECT ID FROM tblItems WHERE number = $place
Does that help?
-Mike
> -----Original Message-----
> From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com]
> Sent: Tuesday, July 29, 2003 1:31 PM
> To: Mike At Spy; [email]php-general@lists.php.net[/email]
> Subject: RE: [PHP] Bizarre SQl, if issue....
>
>
> [snip]
> $person = mysql_query("Some Statement Here");
>
> if (!$person || $person == 0 || $person == '' || $person == '0') {
> $result =
> 1; }
> else { $result = 4; }
>
> If the SQL statement returns an empty set, shouldn't $result be equal to
> 1?
> Instead, I'm getting $result = 4.
> [/snip]
>
> Actually I think we need to see the query == "Some Statement Here".
> $person in this case is either TRUE or FALSE
>
>Mike At Spy Guest
-
Jay Blanchard #4
RE: [PHP] Bizarre SQl, if issue....
[snip]
Here's the SQL - I tested it via command line and it comes back empty
set.
SELECT ID FROM tblItems WHERE number = $placeto>
> [snip]
> $person = mysql_query("Some Statement Here");
>
> if (!$person || $person == 0 || $person == '' || $person == '0') {
> $result =
> 1; }
> else { $result = 4; }
>
> If the SQL statement returns an empty set, shouldn't $result be equal[snip]> 1?
> Instead, I'm getting $result = 4.
> [/snip]
>
> Actually I think we need to see the query == "Some Statement Here".
> $person in this case is either TRUE or FALSE
So ...
$person = mysql_query("SELECT ID FROM tblItems WHERE number = $place");
$person IS TRUE because query executed (the OR statements do not count
as $person can only be TRUE or FALSE, so you can drop the OR's);
if(!$person){ // tests to see if person IS FALSE
$result = 1;
} else {
$result = 4;
}
$result will be 4
If you do this;
if($person){ // tests to see if person IS TRUE
$result = 1;
} else {
$result = 4;
}
$result would be 1
Now, if you used mysql_num_rows($person)
$thecount = mysql_num_rows($person);
if($thecount == 0){ // tests for zero
$result = 1;
} else {
$result = 4;
}
$result will be 1
if(!$thecount == 0){ // tests for other than zero
$result = 1;
} else {
$result = 4;
}
$result will be 4
HTH
Jay Blanchard Guest
-
Jay Blanchard #5
RE: [PHP] Bizarre SQl, if issue....
[snip]
....lots of stuff...
[/snip]
What I forgot to say is that basically you were testing for query
execution, not the number of rows returned from the database. If you
want to test the number of rows or some other result from the query you
have to go further.
HTH!
Jay Blanchard Guest
-
Mike Ford #6
RE: [PHP] Bizarre SQl, if issue....
> -----Original Message-----
> From: Mike At Spy [mailto:spycobalt@spyproductions.com]
> Sent: 29 July 2003 18:37Please go back and read the manual page for mysql_query again ([url]http://www.php.net/mysql_query[/url]).> >
> > $person = mysql_query("Some Statement Here");
The above returns FALSE if the query is invalid, or a resource_id you can use to fetch the result (or information about it). So most likely $person is now a MySQL resource id that doesn't match any of the conditions in your if statement, and also (more importantly) doesn't tell you whether you have an empty set or not. I'd suggest mysql_num_rows() for that.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: [email]m.ford@lmu.ac.uk[/email]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Mike Ford Guest
-
Jay Blanchard #7
RE: [PHP] Bizarre SQl, if issue....
[snip]
I know. I first tested for !$person but got the TRUE result when I
should
have received FALSE (empty set).
Why would that be?
I added '0' and such just to see if I wasn't thinking straight..... :\
-Mike
[/snip]
If the query executes it will return TRUE for $person, so
if(!$person) would read IF THE QUERY IS NOT TRUE
if($person) would read IF THE QUERY IS TRUE
Jay Blanchard Guest
-
Jay Blanchard #8
RE: [PHP] Bizarre SQl, if issue....
[snip]
Off hand, I would agree. And that is what I would expect.
However, the *exact* same setup on a different server gives me a result
of
'FALSE' properly. The other server has php 4.3.3 on it - the one giving
the
improper response has php 4.1.2.
Could this be the issue?
[/snip]
It sounds unlikely. The point is, what are you needing to test for? Do
you need to know that the query executed or do you need to test the
results of the query for a particular condition?
Jay Blanchard Guest
-
Mike At Spy #9
RE: [PHP] Bizarre SQl, if issue....
Off hand, I would agree. And that is what I would expect.
However, the *exact* same setup on a different server gives me a result of
'FALSE' properly. The other server has php 4.3.3 on it - the one giving the
improper response has php 4.1.2.
Could this be the issue?
-Mike
> -----Original Message-----
> From: Ford, Mike [LSS] [mailto:M.Ford@lmu.ac.uk]
> Sent: Tuesday, July 29, 2003 1:47 PM
> To: 'Mike At Spy'; [email]php-general@lists.php.net[/email]
> Subject: RE: [PHP] Bizarre SQl, if issue....
>
>>> > -----Original Message-----
> > From: Mike At Spy [mailto:spycobalt@spyproductions.com]
> > Sent: 29 July 2003 18:37>> > >
> > > $person = mysql_query("Some Statement Here");
> Please go back and read the manual page for mysql_query again
> (http://www.php.net/mysql_query).
>
> The above returns FALSE if the query is invalid, or a resource_id
> you can use to fetch the result (or information about it). So
> most likely $person is now a MySQL resource id that doesn't match
> any of the conditions in your if statement, and also (more
> importantly) doesn't tell you whether you have an empty set or
> not. I'd suggest mysql_num_rows() for that.
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
>
>
Mike At Spy Guest
-
Mike Ford #10
RE: [PHP] Bizarre SQl, if issue....
> -----Original Message-----
Hang on -- it's not clear to me which server is giving which response.> From: Mike At Spy [mailto:spycobalt@spyproductions.com]
> Sent: 29 July 2003 19:01
>
> Off hand, I would agree. And that is what I would expect.
>
> However, the *exact* same setup on a different server gives
> me a result of
> 'FALSE' properly. The other server has php 4.3.3 on it - the
> one giving the
> improper response has php 4.1.2.
Just to be clear, the proper response is to deliver a resource id if the query is valid, or FALSE if not. Could it be that one server is consistently giving you a resource ID of 0, and the other isn't? (I'm not even sure if a resource ID of zero is equivalent to a real zero, or what the result of doing an if ($resource_id) on it would be, but this might be a straw to clutch at!). To see *exactly* what's being returned into $person from your mysql_query(), try doing var_dump($person).
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: [email]m.ford@lmu.ac.uk[/email]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Mike Ford Guest
-
Mike At Spy #11
RE: [PHP] Bizarre SQl, if issue....
> [snip]
> Off hand, I would agree. And that is what I would expect.
>
> However, the *exact* same setup on a different server gives me a result
> of
> 'FALSE' properly. The other server has php 4.3.3 on it - the one giving
> the
> improper response has php 4.1.2.
$which_person = mysql_query("SELECT ID FROM tblItems WHERE number =
$place");
$vthere = mysql_num_rows($which_person);
if ($vthere == '0') { True } else { False }
What should this return? True or False?
-Mike
Mike At Spy Guest
-
Jay Blanchard #12
RE: [PHP] Bizarre SQl, if issue....
[snip]
$which_person = mysql_query("SELECT ID FROM tblItems WHERE number =
$place");
$vthere = mysql_num_rows($which_person);
if ($vthere == '0') { True } else { False }
What should this return? True or False?
[/snip]
If there is one or more rows returned by the query False, if zero rows
are returned then True.
Jay Blanchard Guest
-
Mike At Spy #13
RE: [PHP] Bizarre SQl, if issue....
I did the var_dump and got:
bool(false)
While $vthere (from my previous post) returns 0 (zero) still. :\
But proceeds as if 0 were a false statement when asked if $vthere equals
zero. :\
-Mike
> -----Original Message-----
> From: Ford, Mike [LSS] [mailto:M.Ford@lmu.ac.uk]
> Sent: Tuesday, July 29, 2003 2:07 PM
> To: 'Mike At Spy'; Ford, Mike [LSS]; [email]php-general@lists.php.net[/email]
> Subject: RE: [PHP] Bizarre SQl, if issue....
>
>>> > -----Original Message-----
> > From: Mike At Spy [mailto:spycobalt@spyproductions.com]
> > Sent: 29 July 2003 19:01
> >
> > Off hand, I would agree. And that is what I would expect.
> >
> > However, the *exact* same setup on a different server gives
> > me a result of
> > 'FALSE' properly. The other server has php 4.3.3 on it - the
> > one giving the
> > improper response has php 4.1.2.
> Hang on -- it's not clear to me which server is giving which response.
>
> Just to be clear, the proper response is to deliver a resource id
> if the query is valid, or FALSE if not. Could it be that one
> server is consistently giving you a resource ID of 0, and the
> other isn't? (I'm not even sure if a resource ID of zero is
> equivalent to a real zero, or what the result of doing an if
> ($resource_id) on it would be, but this might be a straw to
> clutch at!). To see *exactly* what's being returned into $person
> from your mysql_query(), try doing var_dump($person).
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Mike At Spy Guest
-
Jay Blanchard #14
RE: [PHP] Bizarre SQl, if issue....
[snip]
I did the var_dump and got:
bool(false)
While $vthere (from my previous post) returns 0 (zero) still. :\
But proceeds as if 0 were a false statement when asked if $vthere equals
zero. :\
-Mike
[/snip]
Is the query executing properly? Try this ...
$sql = "SELECT ID from tblItems WHERE number = '" . $place . "' ");
if(!($person = mysql_query($sql, $connect_variable))){
print(mysql_error() . "\n");
exit();
}
It is a verbose test
Jay Blanchard Guest
-
Mike At Spy #15
RE: [PHP] Bizarre SQl, if issue....
Nothin' wrong with the SQL statement - it executes properly when I enter
values that actually pull something from a table. When I enter values that
are not present in the table, I go on to have the other issue of it looking
like it is false, though it is not. :\
-Mike
> -----Original Message-----
> From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com]
> Sent: Tuesday, July 29, 2003 2:24 PM
> To: Mike At Spy; Ford, Mike [LSS]; [email]php-general@lists.php.net[/email]
> Subject: RE: [PHP] Bizarre SQl, if issue....
>
>
> [snip]
> I did the var_dump and got:
>
> bool(false)
>
> While $vthere (from my previous post) returns 0 (zero) still. :\
>
> But proceeds as if 0 were a false statement when asked if $vthere equals
> zero. :\
>
> -Mike
> [/snip]
>
> Is the query executing properly? Try this ...
>
> $sql = "SELECT ID from tblItems WHERE number = '" . $place . "' ");
> if(!($person = mysql_query($sql, $connect_variable))){
> print(mysql_error() . "\n");
> exit();
> }
>
> It is a verbose test
>
>
Mike At Spy Guest
-
Jay Blanchard #16
RE: [PHP] Bizarre SQl, if issue....
[snip]
Nothin' wrong with the SQL statement - it executes properly when I enter
values that actually pull something from a table. When I enter values
that
are not present in the table, I go on to have the other issue of it
looking
like it is false, though it is not. :\
[/snip]
But you are testing the query from the command line, I want to test it
from within the confines of the PHP script. Humor me?
Jay Blanchard Guest
-
David Nicholson #17
Re: [PHP] Bizarre SQl, if issue....
Hello,
This is a reply to an e-mail that you wrote on Tue, 29 Jul 2003 at
18:57, lines prefixed by '>' were originally written by you.mysql_query() returns FALSE if the query fails and a resource ID if> Off hand, I would agree. And that is what I would expect.
> However, the *exact* same setup on a different server gives me a
> result of
> 'FALSE' properly. The other server has php 4.3.3 on it - the one
> giving the
> improper response has php 4.1.2.
> Could this be the issue?
> -Mike
it suceeds in both of those versions. The best way to see if it
failed or not is...
$queryid = mysql_query($sql);
if($queryid !== FALSE){
// this will be evaluated if mysql_wuery did not return FALSE
// and it is type-sensitive so (int)0 does not count as FALSE.
}
--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: [url]http://www.phpmachine.com/[/url]
Professional Web Development by David Nicholson
[url]http://www.djnicholson.com/[/url]
QuizSender.com - How well do your friends actually know you?
[url]http://www.quizsender.com/[/url]
(developed entirely in PHP)
David Nicholson Guest
-
Jay Blanchard #18
RE: [PHP] Bizarre SQl, if issue....
[snip]
Value. If there is nothing found in the table that matches, do one> I still want to know what you need to do, test for query execution or
> value? It is pretty cut and dried after that.
thing.
If there is, do another. :)
[/snip]
Then you must test for something returned, not whether or not the query
executed. Use mysql_num_rows($person);
Jay Blanchard Guest
-
Mike At Spy #19
RE: [PHP] Bizarre SQl, if issue....
I did! Look at this again:> -----Original Message-----
> From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com]
> Sent: Tuesday, July 29, 2003 2:41 PM
> To: Mike At Spy; [email]php-general@lists.php.net[/email]
> Subject: RE: [PHP] Bizarre SQl, if issue....
>
>
> [snip]>> > I still want to know what you need to do, test for query execution or
> > value? It is pretty cut and dried after that.
> Value. If there is nothing found in the table that matches, do one
> thing.
> If there is, do another. :)
> [/snip]
>
> Then you must test for something returned, not whether or not the query
> executed. Use mysql_num_rows($person);
$which_person = mysql_query("SELECT ID FROM tblItems WHERE number =
$place");
$vthere = mysql_num_rows($which_person);
if ($vthere == '0') { True } else { False }
Yet it still returns as if this is FALSE (i.e. it executes the else {}. :\
:\
-Mike
Mike At Spy Guest
-
David Nicholson #20
Re: [PHP] Bizarre SQl, if issue....
Hello,
This is a reply to an e-mail that you wrote on Tue, 29 Jul 2003 at
19:46, lines prefixed by '>' were originally written by you.number => I did! Look at this again:
> $which_person = mysql_query("SELECT ID FROM tblItems WHEREelse> $place");
> $vthere = mysql_num_rows($which_person);
> if ($vthere == '0') { True } else { False }
> Yet it still returns as if this is FALSE (i.e. it executes theAs long as your query is returning 0 rows that code should work ok,> {}. :
but it is incorrect for correctness,
if ($vthere == '0')
should be
if ($vthere == 0)
As $vthere will contain an integer, not a string, but as you are
using the == comparison operator instead of === PHP should
convert them both to the same type before comparing.
Can we see the snippet of the actual code that you are using?
David.
--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: [url]http://www.phpmachine.com/[/url]
Professional Web Development by David Nicholson
[url]http://www.djnicholson.com/[/url]
QuizSender.com - How well do your friends actually know you?
[url]http://www.quizsender.com/[/url]
(developed entirely in PHP)
David Nicholson Guest



Reply With Quote

