php - How to get last value from mysql record -
i'm php beginner please me..
i have mysql record bellow
id name value_1 value_2 1 rakesh 100 50 2 david 150 10 3 richard 0 0 4 michael 0 0
i want last record value_1 math if last record value_1==0 means want go , upper top value_1 (value_1=150)
i use bellow code last value
$get=mysql_query("select max(id) table_name "); $got = mysql_fetch_array($get); $next_id = $got['max(id)'];
here 3d richard value_1==0 want 2nd david value_1 150
please me in advance...
your query giving last row, because selecting biggest id.
try that:
select * table_name value_1 > 0 order value_1 desc limit 1
- it select whole row won't need make additional query.
where value_1
> 0 select rowsvalue_1
bigger 0. assumes such records exists though. let me know if not case.order value_1 desc
tells query order rowsvalue_1
in descending order , desired row on top.limit 1
selects first row only.
Comments
Post a Comment