FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » query with empty resultset (but the same one, used in phpmyadmin, gives results!!)
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
query with empty resultset (but the same one, used in phpmyadmin, gives results!!) [message #175349] Sat, 10 September 2011 10:41 Go to next message
SatBoy78 is currently offline  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 #175350 is a reply to message #175349] Sat, 10 September 2011 11:34 Go to previous messageGo to next message
SatBoy78 is currently offline  SatBoy78
Messages: 2
Registered: September 2011
Karma: 0
Junior Member
solved!

the problem was $month=09;

correct is $month=9;
Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) [message #175353 is a reply to message #175350] Sat, 10 September 2011 12:32 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/10/2011 7:34 AM, SatBoy78 wrote:
> solved!
>
> the problem was $month=09;
>
> correct is $month=9;

When you have problems with a database query, you should echo the query
you are issuing. Then if the problem is not obvious, you should almost
always ask in a database newsgroup.

The solution may end up being in PHP - but PHP knows nothing about SQL
and that's where your diagnosis should start.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
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 Go to previous messageGo to next message
Norman Peelman is currently offline  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 Go to previous messageGo to next message
Denis McMahon is currently offline  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
Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) [message #175365 is a reply to message #175350] Mon, 12 September 2011 06:16 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 10/09/2011 13:34, SatBoy78 escribió/wrote:
> solved!
>
> the problem was $month=09;
>
> correct is $month=9;

It it wasn't true that it was the same query, was it? :)

Sorry if I'm stating the obvious but the MySQL server cannot see your
PHP code. You use PHP to compose a string that contains a SQL query and
that SQL code is all that MySQL care about. So next time start your
debugging by inspecting the *generated* SQL code.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: HOW TO: Spice up Your Site With Simple PHP
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 09:24:27 GMT 2024

Total time taken to generate the page: 0.07000 seconds