0

hi i have this mysql statement without limit so it will get first row in ascending order but i want to get the title of second row as well

    $res = mysql_query("select * from tas where id='{$m_id}' ");

after that i can fetch and get the first output without any issue earlier i was required to get the id so i used this

   $nidf=$m_id-1;

but now i need title of previous id.table consists if id,title,views etc .i know it can be done easily by this query

    $res2 = mysql_query("select * from tas where id='{$nidf}' ");

but i dont want to execute second syl query and i want to learn how it can be done without using above query

i cant not use while as i need only second title and rest of the thigs i need for first row only

1

1 Answer 1

2
SELECT *
FROM tas
WHERE id <= $m_id
ORDER BY id DESC
LIMIT 2

fetch all the rows that have your specified ID OR* LESS, order by that id in descending order, then return only the first 2 rows in that ordered set. That'll be the $m_id you wanted, and the next immediately lower id as well.

Sign up to request clarification or add additional context in comments.

1 Comment

i am using $row = mysql_fetch_array($res); and after that $output=$row['title']; which will give output of first row how to get for second row

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.