开发者

Echoing out a date from a query

开发者 https://www.devze.com 2023-04-01 02:39 出处:网络
I would like $minutes below to be the oldest datecommented from the query (expressed in minutes).When I echo 开发者_运维百科$minutes out, I get a blank result.What am I doing wrong?

I would like $minutes below to be the oldest datecommented from the query (expressed in minutes). When I echo 开发者_运维百科$minutes out, I get a blank result. What am I doing wrong?

$queryuidcount = "SELECT loginid, datecommented 
    FROM comment 
   WHERE (HOUR(NOW()) - HOUR(datecommented)) <= 1 
     AND loginid = '$uid' 
ORDER BY datecommented ASC
   LIMIT 1'"; 
$row2 = mysql_fetch_array($queryuidcount);
$minutes = $row2["datecommented"];


You need to execute mysql_query() on your query before you call mysql_fetch_array() on the result. Try this:

$result = mysql_query('SELECT loginid, datecommented FROM comment WHERE (HOUR(NOW()) - HOUR(datecommented)) <= 1 AND loginid = '$uid' ORDER BY datecommented ASC LIMIT 1');

$row = mysql_fetch_array($result);

$minutes = $row['datecommented'];

If your query returns multiple rows, you'll need to iterate through them with a while loop:

while($row = mysql_fetch_array($result)) {
    //Fetch values from $row
}

Also, consider using PDO instead of the mysql function family.


I think you are doing it in the wrong way. Here you can find some examples.

mysql_fetch_array is not for DB connection or sql query.

http://php.net/manual/en/function.mysql-fetch-array.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号