Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3104 > unrolled thread

query with empty resultset (but the same one, used in phpmyadmin, gives results!!)

Started bySatBoy78 <bruno.matteo@gmail.com>
First post2011-09-10 03:41 -0700
Last post2011-09-10 09:00 -0400
Articles 6 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  query with empty resultset (but the same one, used in phpmyadmin, gives results!!) SatBoy78 <bruno.matteo@gmail.com> - 2011-09-10 03:41 -0700
    Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) SatBoy78 <bruno.matteo@gmail.com> - 2011-09-10 04:34 -0700
      Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) Jerry Stuckle <jstucklex@attglobal.net> - 2011-09-10 08:32 -0400
      Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) Denis McMahon <denis.m.f.mcmahon@gmail.com> - 2011-09-11 11:45 +0000
      Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-09-12 08:16 +0200
    Re: query with empty resultset (but the same one, used in phpmyadmin, gives results!!) Norman Peelman <npeelmandog@cfl.rr.com> - 2011-09-10 09:00 -0400

#3104 — query with empty resultset (but the same one, used in phpmyadmin, gives results!!)

FromSatBoy78 <bruno.matteo@gmail.com>
Date2011-09-10 03:41 -0700
Subjectquery with empty resultset (but the same one, used in phpmyadmin, gives results!!)
Message-ID<14f2e3aa-e019-4c87-a87b-1329a63c1e37@u20g2000yqj.googlegroups.com>
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

[toc] | [next] | [standalone]


#3105

FromSatBoy78 <bruno.matteo@gmail.com>
Date2011-09-10 04:34 -0700
Message-ID<5603e5a5-ed19-44f8-9bc2-4ba707a3a7d6@d18g2000yqm.googlegroups.com>
In reply to#3104
solved!

the problem was $month=09;

correct is $month=9;

[toc] | [prev] | [next] | [standalone]


#3108

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-09-10 08:32 -0400
Message-ID<j4fldd$85b$1@dont-email.me>
In reply to#3105
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#3113

FromDenis McMahon <denis.m.f.mcmahon@gmail.com>
Date2011-09-11 11:45 +0000
Message-ID<4e6c9f56$0$26368$a8266bb1@newsreader.readnews.com>
In reply to#3105
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

[toc] | [prev] | [next] | [standalone]


#3120

From"Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Date2011-09-12 08:16 +0200
Message-ID<j4k83t$toc$2@dont-email.me>
In reply to#3105
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
--

[toc] | [prev] | [next] | [standalone]


#3109

FromNorman Peelman <npeelmandog@cfl.rr.com>
Date2011-09-10 09:00 -0400
Message-ID<j4fn0u$hhb$1@dont-email.me>
In reply to#3104
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?-

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web