如何获取所选表的第一行

时间:2017-11-27 13:45:05

标签: php mysql

我需要获取所选表格的第一行和特定列值:

   $ttleft = '';
    $st = $db->query("select * from recipes order by inde asc");
    while($row = $st->fetch()){
        $ttleft .= "<div class='ttleft'>" . $row['title'] . "</div>\n";
        // result: 323 525 727 - that's ok
        $ttop = $row['title'];
        // result: 727 - I need 323
    }

1 个答案:

答案 0 :(得分:1)

如果您希望ASC订单中的$ttleft$ttop等于最小

$ttleft = '';
$st = $db->query("select * from recipes order by inde asc");
while($row = $st->fetch()){
    $ttleft .= "<div class='ttleft'>" . $row['title'] . "</div>\n";
    // result: 323 525 727 - that's ok
    if(!isset($ttop)){ 
        $ttop = $row['title']; 
        //result: 323
    }
}

否则,如果您不关心$ttleft只是通过desc命令

的顺序
$st = $db->query("select * from recipes order by inde desc");