dtio35880438 2014-05-03 17:56
浏览 50
已采纳

将表拆分为组 - PHP和MYSQL

The table name is racecard. Today, there are 9 races.

The table structure looks like this:

RaceNo HorseNo HorseName

1   1   FAJR 
1   2   CUT DIAMOND 
1   3   VOICE OF FAITH 
1   4   CEASARINA 
1   5   JAIPUR GEM 
1   6   KATNISS 
1   7   PLAN B 
1   8   CLASSY DANCER 
1   9   RAJASTHAN GLORY 
1   10  HIGHWAY EXPRESS 
1   11  TAJ E SHAHI 
2   1   VICTORIOUS MARCH 
2   2   DEMONSTRATOR 
2   3   MYLA ROSE 
2   4   RIO 
2   5   MONZA 
3   1   TITLEIST 
3   2   SUNTAN BEAUTY 
3   3   VICTORIAN 
3   4   LAURUS PRIDE 

...

I am trying to create a PHP page in that the entire table is grouped by race no.

The page should have the sub-headings like Race No -1, Race No - 2:

Race No: 1

HorseNo Horse Name Win bet Show bet Place bet

1   FAJR                          textbox         textbox          textbox 

2   CUT DIAMOND                   textbox         textbox          textbox 

3   VOICE OF FAITH                textbox         textbox          textbox 

4   CEASARINA                     textbox         textbox          textbox 

5   JAIPUR GEM                    textbox         textbox          textbox 

6   KATNISS                       textbox         textbox          textbox 

7   PLAN B                        textbox         textbox          textbox 

8   CLASSY DANCER                 textbox         textbox          textbox 

9   RAJASTHAN GLORY               textbox         textbox          textbox 

10  HIGHWAY EXPRESS               textbox         textbox          textbox 

11  TAJ E SHAHI                   textbox         textbox          textbox

Race No: 2

HorseNo Horse Name Win bet Show bet Place bet

1   VICTORIOUS MARCH              textbox         textbox          textbox

2   DEMONSTRATOR                  textbox         textbox          textbox

3   MYLA ROSE                     textbox         textbox          textbox

4   RIO                           textbox         textbox          textbox

5   MONZA                         textbox         textbox          textbox

and so on. Also, there should be columns with text boxes for entering the bet amounts. When the user submits the form, the betting details should be stored in the betting table with respective race no, horse no and bet amount. I need to use array. Please help me in coding.

  • 写回答

2条回答 默认 最新

  • duanfu1945 2014-05-03 18:56
    关注

    first determine the highest RaceNo.

    SELECT RaceNo AS RaceNoMAX FROM racecard WHERE RaceNo=max(RaceNo)
    

    then make a for or a while loop with a function to draw the table

    While ($i<RaceNoMAX ){
       $sql = "SELECT HorseNo, Horse Name, Win_bet, Show_bet, Place_bet 
       FROM racecard 
       WHERE RaceNo=$i ORDER BY HorseNo ASC";
    
    $result = ...;
    
    $php_function_to_draw_the_table = ...;
    
    $++;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图