我的php代码无法选择mysql auto_increment值

时间:2013-08-13 13:11:23

标签: php mysql while-loop auto-increment

function shopView(){
        global $core;
        $shop = mysql_query("SELECT * FROM services ORDER BY id DESC");
        $return = '<article>';
        if($shop){
        while ($row = mysql_fetch_array($shop)) {
            $return .= '<h4>'.$row['nazwa'].'</h4><a href="index.php?view=buy&service='.$row['id'].'" class="button">Kup za '.$row['koszt'].' zl (+vat)</a>';
            }
        }
        else{
            $return .= 'Niestety coś poszło nie tak ;/';
        }
        $return .= '</article>';
        return $return;
    }

我不知道为什么这个$row['id']不起作用。我有一些类似的代码,并且有相同的代码,如?value='.$query['auto_increment'].',一切都很好。有人能帮助我吗?

1 个答案:

答案 0 :(得分:2)

使用以下代码

function shopView(){
    global $core;
    $shop = mysql_query("SELECT * FROM services ORDER BY id DESC");
    $return = '<article>';
    if($shop){
    while ($row = mysql_fetch_array($shop,MYSQL_ASSOC)) {
        $return .= '<h4>'.$row['nazwa'].'</h4><a href="index.php?view=buy&service='.$row['id'].'" class="button">Kup za '.$row['koszt'].' zl (+vat)</a>';
        }
    }
    else{
        $return .= 'Niestety coś poszło nie tak ;/';
    }
    $return .= '</article>';
    return $return;
}

referencess http://php.net/manual/en/function.mysql-fetch-array.php