需要帮助才能找到php结构解决方案


need help to find a php structure solution

我只是php的一名学生,我正试图从一个表中找出一个成员列表,我不知道该表中有多少行,但我需要每6行Order By entrytime DESC。我的表格结构如下:

int `ID`
int `entrytime` // this time updates when rows insert

现在我需要在entrytime DESC的基础上找出所有的id,并将这些id插入一个单独的新表中,比如"new_tbl",作为一组6个id的

ind `ID`
varchar `group_name`

我正试着这样做:

$qry=mysql_query("SELECT id FROM main_table entrytime ASC");
while($res=mysql_fetch_row($qry)){
    $id=$res['0'];
    $q=mysql_query();
######### But not getting any Idea how to find every 6 Ids and insert in new_tbl #######
}

在您使用mysql_fetch_row的情况下,它提供的是行数,而不是数据。

while($res=mysql_fetch_assoc($qry)) {

要获得数据,您必须使用例如mysql_fetch_assoc

要查找每6个Id,可以制作一个计数器并将值递增1。如果6的模和值为0,则有第六个值,可以重置计数器。

$i = 1;
while ... 
   if($i % 6 == 0) {
      // reset your counter
      $i = 1;
   }
   $i++;
}

然后,您可以使用计数器来处理它,并将其写入另一个表,例如。