2015-11-24 122 views
0

我試圖做一個測試表單(嚮導),並在每一步(選項卡)我從$步查詢所有行,而不是我需要的。 在數據庫中的表看起來像這樣Mysql顯示所有不只是選擇

//main_steps 
id_main_steps = 1...40 
step_number = 5.[1..40] 

//vpf_steps 
step = 5.[1..40].[1..x] 

//code 
$main = mysql_query("select * from main_steps")or die(mysql_error()); 
while($row1 = mysql_fetch_array($main)){ 
echo "<div class=\"tab-pane\" id=\"tab5".$row1['id_main_steps']."\">".$row1['step_number']."-".$row1['step_measurement']."</div>"; 
$step = mysql_query("SELECT * FROM vpf_steps where step like '".$row1['step_number'].".%'")or die(mysql_error()); 
while($row2 = mysql_fetch_array($step)){ 
    echo " 
    <div class=\"form-group\"> 
    <div class=\"row\"> 
     <div class=\"col-md-2\">".$row2['step']."</div> 
     <div class=\"col-md-4\">".$row2['measurement']."</div> 
     <div class=\"col-md-2\"><input type=\"".$row2['input_type']."\" class=\"form-control\" name=\"".$row2['step']."\"></div> 
    </div> 
    </div>"; 
} 
} 

UPDATE 表結構 主要步驟

id_main_steps | step_number | step_measurement 
     1  |  5.01 | main_step1 
     2  |  5.02 | main_step2 
.... 

vpf_steps

id_vpf_steps | step  | measurement 
     1  | 5.01.01  | step1_1 
     2  | 5.01.02  | step1_2 
     3  | 5.01.03  | step1_3 
     4  | 5.02.01  | step2_1 
     5  | 5.02.01  | step2_2 
.... 

和輸出應該是這樣的

但我得到的是

on tab1 
5.01 main_step1 
    5.01.01 step1_1 
    5.01.02 step1_2 
    5.01.03 step2_3 
    5.02.01 step2_1 
    5.02.01 step2_1 


on tab2 
    5.01.01 step1_1 
    5.01.02 step1_2 
    5.01.03 step2_3 
5.02 main_step2 
    5.02.01 step2_1 
    5.02.01 step2_1 
+0

請提供表結構,一些示例數據和預期輸出! – Shadow

+0

我已更新該問題 – xlucian

回答

0

這一切固定

  $main = mysql_query("select * from main_steps")or die(mysql_error()); 
      while($row1 = mysql_fetch_array($main)){ 
       echo "<div class=\"tab-pane\" id=\"tab5".$row1['id_main_steps']."\">".$row1['step_number']."-".$row1['step_measurement'].""; 
       $step = mysql_query("SELECT * FROM vpf_steps where step like '".$row1['step_number'].".%'")or die(mysql_error()); 
       while($row2 = mysql_fetch_array($step)){ 
        echo " 
         <div class=\"form-group\"> 
          <div class=\"row\"> 
           <div class=\"col-md-2\">".$row2['step']."</div> 
           <div class=\"col-md-4\">".$row2['measurement']."</div> 
           <div class=\"col-md-2\"><input type=\"".$row2['input_type']."\" class=\"form-control\" name=\"".$row2['step']."\"></div> 
          </div> 
         </div>"; 
       } 
       echo "</div>"; 
      }