[ale] PHP Guru

Chuck Payne terrorpup at gmail.com
Thu Jan 31 16:15:23 EST 2013


On Thu, Jan 31, 2013 at 1:57 PM, Alex Carver <agcarver+ale at acarver.net> wrote:
> On 1/31/2013 10:44, Chuck Payne wrote:
>>
>> Guys,
>>
>> I need help from php guru.
>>
>> I have sql statement that works great in mysql, where I'm am using
>> datediff. When I try to use it in php, I get an "mysql_fetch_arrary()
>> expects parameter 1 to be a resource, boolean given in"
>>
>> This the statement is...
>>
>> $result = mysql_query("select hname, hsn, hmodel, hmake, htype, hwar,
>> datediff(`hwar`, now()) from host where stype='physical';",$db);
>>
>> I know the statement works in mysql
>>
>> mysql> select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`,
>> now()) from servers.host where stype='physical';
>>
>> +--------------+---------+--------+-----------+-------+------------+-------------------------+
>> | hname        | hsn     | hmodel | hmake     | htype | hwar       |
>> datediff(`hwar`, now()) |
>>
>> +--------------+---------+--------+-----------+-------+------------+-------------------------+
>> | moscow       | XXXXXXX | Dell   | PowerEdge | R710  | 2013-09-13 |
>>                    225 |
>> | sydney       | XXXXXXX | Dell   | PowerEdge | R710  | 2013-09-15 |
>>                    227 |
>>
>>
>> When I remove datediff(`hwar`, now()), my page works.  I wanted to use
>> that as field
>>
>> $datediff=$row['datediff'];
>>
>> Any clues as to why it doesn't work?
>>
>
>
> It doesn't work because the index in the PHP array isn't "datediff" it's
> "datediff (`hwar`, now())".  The indexes returned in the mysql result arrays
> are EXACTLY as you see the header columns in the straight mysql output that
> you have listed and you can see the datediff column header is not just
> "datediff".  That's just how PHP's mysql library works.  You need to alias
> the column to give it a name that PHP can use.
>
> mysql_query("select ..., datedif(`hwar`, now()) AS mydatediff ... ")
>
> Then you reference it as $row['mydatediff'];
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo


Thanks that fixed it. Also, is the code for mysql different from
mysqli? I was told I need to use that now.
-- 
Terror PUP a.k.a
Chuck "PUP" Payne

(678) 636-9678
-----------------------------------------
Discover it! Enjoy it! Share it! openSUSE Linux.
-----------------------------------------
openSUSE -- en.opensuse.org/User:Terrorpup
openSUSE Ambassador/openSUSE Member
Community Manager -- Southeast Linux Foundation (SELF)
skype,twiiter,identica,friendfeed -- terrorpup
freenode(irc) --terrorpup/lupinstein
Register Linux Userid: 155363

Have you tried SUSE Studio? Need to create a Live CD,  an app you want
to package and distribute , or create your own linux distro. Give SUSE
Studio a try. www.susestudio.com.
See you at Southeast Linux Fest, June 7-9, 2013 in Charlotte, NC.
www.southeastlinuxfest.org


More information about the Ale mailing list