开发者

how to +1 to the MAX record from a field

.i have the following code:

$task_id = mysql_query("SELECT MAX(task_id) from it_task");
echo $task_id;

.what I want to do is to get the highest value from a field named task_id on the table it_task. Instead of getting a result which is an integ开发者_高级运维er I get "Resource id #5". how do i get around this?


mysql_query generates a resource which you then have to read using another mysql_ function. In this case you'll need a 2nd line to read from the query's result:

$result = mysql_query("SELECT MAX(task_id) from it_task");
$task_id = mysql_result($result, 0, 0); // get the first row, first column
echo $task_id;


Any problem here??? In my postgres sql, I can have:

select max(task_id)+1 as max from it_task;


Yes, mysql_query always returns a resource (unless it returns false), which you have to work on using one of the mysql_ functions like mysql_fetch_assoc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜