query with empty resultset (but the same one, used in phpmyadmin, gives results!!) [message #175349] |
Sat, 10 September 2011 10:41 |
SatBoy78
Messages: 2 Registered: September 2011
Karma: 0
|
Junior Member |
|
|
Hi, I'm having some problems with a query, that gives results if used
in phpmyadmin, but when I use it in my php page I'll get an empty
resultset
the query is
select * from brucisys_homecalciobet.bollahome where (DAY(Data)
between 9 and 11) and (MONTH(Data) = 9) and (YEAR(Data) = 2011)
and, as told, gives some results
in my php page I've written this:
$dayStart=9;
$dayEnd=11;
$month=09;
$year=2011;
$rs0 = mysql_query("select * from brucisys_homecalciobet.bollahome
where (DAY(Data) between ".$dayStart." and ".$dayEnd.") and
(MONTH(Data) = ".$month.") and (YEAR(Data) = ".$year.")");
but the resultset is empty; infact I've done this little test
$returned_rows = mysql_num_rows ($rs0); echo "n. ".$returned_rows;
and it shows n. 0
Do you have any idea? wherei'm wrong?
Thanks a lot for your help
Have a nice day
|
|
|
|
|
Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) [message #175354 is a reply to message #175349] |
Sat, 10 September 2011 13:00 |
Norman Peelman
Messages: 126 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 09/10/2011 06:41 AM, SatBoy78 wrote:
> Hi, I'm having some problems with a query, that gives results if used
> in phpmyadmin, but when I use it in my php page I'll get an empty
> resultset
>
> the query is
>
> select * from brucisys_homecalciobet.bollahome where (DAY(Data)
> between 9 and 11) and (MONTH(Data) = 9) and (YEAR(Data) = 2011)
>
> and, as told, gives some results
>
>
> in my php page I've written this:
>
> $dayStart=9;
> $dayEnd=11;
> $month=09;
> $year=2011;
>
> $rs0 = mysql_query("select * from brucisys_homecalciobet.bollahome
> where (DAY(Data) between ".$dayStart." and ".$dayEnd.") and
> (MONTH(Data) = ".$month.") and (YEAR(Data) = ".$year.")");
>
> but the resultset is empty; infact I've done this little test
>
> $returned_rows = mysql_num_rows ($rs0); echo "n. ".$returned_rows;
>
> and it shows n. 0
>
>
> Do you have any idea? wherei'm wrong?
>
> Thanks a lot for your help
>
> Have a nice day
I see you found the problem... but as a suggestion you may (or may
not) find:
$rs0 = mysql_query("SELECT * FROM brucisys_homecalciobet.bollahome
WHERE (DAY(Data) BETWEEN $dayStart AND $dayEnd) AND
(MONTH(Data) = $month) AND (YEAR(Data) = $year)");
... a little easier to read. I like to capitalize all SQL keywords
and you can get rid of the pointless string concatination. It's not
needed. You can take a look at:
http://us3.php.net/manual/en/language.operators.string.php
....for examples.
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
|
|
|
Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) [message #175358 is a reply to message #175350] |
Sun, 11 September 2011 11:45 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Sat, 10 Sep 2011 04:34:15 -0700, SatBoy78 wrote:
> solved!
>
> the problem was $month=09;
>
> correct is $month=9;
http://www.php.net/manual/en/language.types.integer.php
$month = 09; // sets $month to the octal value 09, but 9 is an illegal
octal digit, so you actually get 0.
Interestingly, with E_ALL | E_STRICT this particular invalid assignment
doesn't seem to generate any sort of warning, but using an invalid hex
character after 0x does.
<?php
$month = 09;
echo "{$month}\n";
$month = 0Xg; // this is line 4!
echo "{$month}\n";
?>
$ php programming/php/gergberg.php
PHP Parse error: syntax error, unexpected T_STRING in /home/denis/
programming/php/gergberg.php on line 4
$
Rgds
Denis McMahon
|
|
|
|