doufan9805 2014-05-07 20:57
浏览 98
已采纳

使用表格中的所有行获取单元格的数据

I'm trying to figure out how to fetch a cell's data from all rows in a MySQL table and then store the data in an array.

MySQL Table Name = classes

Column      Type                         Comment  
id          int(11)Auto Increment    
name        varchar(75) []    
teacher     varchar(75) []   
cost        decimal(7,0) [0]

I want to create an array using the name value in the table from all the rows (13 total) in the table classes.

I believe I need something like this, but it isn't working.

$names = $db->fetchRows("select `name` from `classes`);

I'm not sure if I should use fetchRow or fetchRows and I'm not sure if I need something after classes.

  • 写回答

1条回答 默认 最新

  • doujiu7680 2014-05-07 20:58
    关注

    If you have your $db class defined somewhere, try this:

    $names = $db->fetchAll("select `name` from `classes`");
    

    If not, you need to read this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?