0

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?

John Conde
  • 217,595
  • 99
  • 455
  • 496
terrorpup
  • 1
  • 1

3 Answers3

0

try to make limit in your query

   $result = mysql_query("select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`, now()) as dif from host where stype='physical' LIMIT 0,10 ;",$db);

look this post

Community
  • 1
  • 1
echo_Me
  • 37,078
  • 5
  • 58
  • 78
0

Try with this:

Replace this piece of sql statement: datediff(hwar, now())

With: datediff(hwar, now()) as Diffdate

And recover it this way: $datediff=$row['Diffdate'];

Bye XD

Hackerman
  • 12,139
  • 2
  • 34
  • 45
0

You should give the selector an alias:

select hname, hsn, hmodel, hmake, htype, hwar, datediff(`hwar`, now()) AS diff from host where stype='physical';

Then you could access the column with the name 'diff'

richjhall18
  • 125
  • 5