Search code examples
phpmysqlselectrow

Select Next mysql row without refer to id


This is My Table:

    #id#    #cpc#
    100      10
     87       9
     101      9
     4        6
     188      5

it's sorted DESC according to 'cpc' column. I Want to extract the rows one by one without referring to id.. such as you can see it.

SELECT * FROM table ORDER BY cpc DESC
first result is with the id 100
next one is with id 101 and cpc 9 not 87.. as the id is only increasing.. so it selects wrong rows not as what i want.


Solution

  • You can do something like this in php:

    $sql = mysql_query("SELECT * FROM yourTable ORDER BY cpc DESC");
    
    while(($row = mysql_fetch_array($sql)){
    $id = $row['id'];
    $cpc = $row['cpc'];