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

Home » Imported messages » comp.lang.php » Pulling my hair out
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Pulling my hair out [message #172404] Wed, 16 February 2011 17:51 Go to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
I have this TRIVIAL code and I am pulling my hair out because of it:

<?php
function getAllEvents() {
$sql = "SELECT * FROM events
WHERE eventDate > NOW()
ORDER BY eventDate LIMIT 4";
print $sql;
$result = mysql_query($sql);
var_dump($result)
$list = array();
while ($row = mysql_fetch_assoc($result)) {
$list[] = $row;
}
return $list;
}

with the two diagnostic included as above. I use the sequel statement
in phpmyadmin and it yields four entries and they are correct. However,
the var_dump results in boolean(false) and no results are extracted (of
course).

The column eventDate is configured as DATE.

I have tried replacing the NOW() with the result of date('Y-m-d'), and
played with many other things including turning things into Unix times.
Nothing worked. Removal of the WHERE clause produced results of the
the first four entries by date in the table.

I simply cannot see why the query works properly when used in
phpmyadmin, but fails here. (Yes, they are going to the same database
and same database table.) It seems so simple and is something I have
done a million times.

What can I be missing?

--
Shelly
Re: Pulling my hair out [message #172405 is a reply to message #172404] Wed, 16 February 2011 18:01 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(sheldonlg)

> I have this TRIVIAL code and I am pulling my hair out because of it:
>
> <?php
> function getAllEvents() {
> $sql = "SELECT * FROM events
> WHERE eventDate > NOW()
> ORDER BY eventDate LIMIT 4";
> print $sql;
> $result = mysql_query($sql);
> var_dump($result)
> $list = array();
> while ($row = mysql_fetch_assoc($result)) {
> $list[] = $row;
> }
> return $list;
> }
>
> with the two diagnostic included as above. I use the sequel statement
> in phpmyadmin and it yields four entries and they are correct. However,
> the var_dump results in boolean(false) and no results are extracted (of
> course).

What does mysql_error() say?

Micha
Re: Pulling my hair out [message #172406 is a reply to message #172404] Wed, 16 February 2011 18:17 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 16/02/11 17:51, sheldonlg wrote:

> $sql = "SELECT * FROM events
> WHERE eventDate > NOW()
> ORDER BY eventDate LIMIT 4";

You want the first 4 future events, yes?

Rgds

Denis McMahon
Re: Pulling my hair out [message #172407 is a reply to message #172405] Wed, 16 February 2011 18:36 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 2/16/2011 1:01 PM, Michael Fesser wrote:
> .oO(sheldonlg)
>
>> I have this TRIVIAL code and I am pulling my hair out because of it:
>>
>> <?php
>> function getAllEvents() {
>> $sql = "SELECT * FROM events
>> WHERE eventDate> NOW()
>> ORDER BY eventDate LIMIT 4";
>> print $sql;
>> $result = mysql_query($sql);
>> var_dump($result)
>> $list = array();
>> while ($row = mysql_fetch_assoc($result)) {
>> $list[] = $row;
>> }
>> return $list;
>> }
>>
>> with the two diagnostic included as above. I use the sequel statement
>> in phpmyadmin and it yields four entries and they are correct. However,
>> the var_dump results in boolean(false) and no results are extracted (of
>> course).
>
> What does mysql_error() say?
>
> Micha

This turns out to be a "forget it and thanks". I was helping my
daughter with this one and the very first thing I asked her when they
came up with different results was "Are you going against the same
database and table?". She said yes, there was only one.

In working with it more today, she removed some zero date entries from
the table and used a workaround that I gave her. They still appeared,
so I asked her once again "Are you going against the same database and
table?". Then she remembered that she had set up a testing server and,
in fact, they were not the same database. Problem solved.

Thanks Micha.

--
Shelly
Re: Pulling my hair out [message #172408 is a reply to message #172406] Wed, 16 February 2011 18:38 Go to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 2/16/2011 1:17 PM, Denis McMahon wrote:
> On 16/02/11 17:51, sheldonlg wrote:
>
>> $sql = "SELECT * FROM events
>> WHERE eventDate> NOW()
>> ORDER BY eventDate LIMIT 4";
>
> You want the first 4 future events, yes?
>
> Rgds
>
> Denis McMahon

Yes. See my response to Micha. It was my daughter's not thinking
clearly in answering my question.

--
Shelly
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Welcome to PhoToZfAiR
Next Topic: PHP Malaysia Meetup 2011 : Framework Shootout
Goto Forum:
  

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

Current Time: Sun Dec 01 06:56:49 GMT 2024

Total time taken to generate the page: 0.02929 seconds