2013-03-14 70 views
-3

嗨繼承人我嘗試的代碼,第一個while語句適用於行(爲權重0工作,但我不能讓它與列(高度)一起工作。如果MIN_HEIGHT輸入值是20,MAX_HEIGHT是50列看起來像這樣20 25 30 35 40 45 50我的代碼當前適用於行而不是列,誰能幫助?PHP我想創建一個HTML表格使用PHP

<?php 
$rowiStep = 5; 
$coliStep = 5; 
// Get these 
$iweightMin = $_GET["min_weight"]; 
$iweightMax = $_GET["max_weight"]; 
$iheightMin = $_GET["max_height"]; 
$iheightmax = $_GET["min_height"]; 

$iCur = $iweightMin; 
$iCol = $iheightMin; 
print('<table class="table">'); 
print('<tr ><td>Height/</br>Weight</td>'); 
while ($iCur <= $iweightMax) { 
    printf('<tr><td>%d</td></tr>', $iCur); 
    $iCur += $rowiStep; 
} 

$rowiCol = $iheightMin; 

while ($iCol <= $iheightmax) { 
    printf('<tr><td></td>', $iCol); 
    $iCol += $rowiCol; 
} 

print ('</tr>'); 
print('</table>'); 

?> 
+2

如果你說你沒有得到列集的輸出,你在列的printf中缺少%d。 – 2013-03-14 21:24:57

+1

HTML表格是逐行形成的,而不是逐列形成的,所以你的方法沒有意義。 – IMSoP 2013-03-14 21:25:44

+0

你能舉一個你想要的輸出的例子,以及用來得到它的輸入嗎? – SomeSillyName 2013-03-14 21:27:11

回答

0

如果你想要打印一個身高/體重矩陣;試試這個:

$rowiStep = 5; 
$coliStep = 5; 
$output = array(
    '<table>' 
); 

for($row_val = $_GET['min_weight'], $row_max <= $_GET['max_weight']; 
    $row_val < $row_max; 
    $row_val += $rowistep) 
{ 
    $output[] = '<tr><td>' . $row_val . '</td>'; 
    for($col_val = $_GET['min_height'], $col_val <= $_GET['max_height']; 
     $col_val < $col_max; 
     $col_val += $colistep) 
    { 
     $output[] = '<td>' . $col_val . '</td>'; 
    } 
    $output[] = '</tr>'; 
} 
$output[] = '</table>'; 
echo implode("\n", $output); 

這將產生像這樣的輸出:

|min_weight   |min_height|min_height+colIStep|min_height+2colIstep|...| 
|min_weight + rowIstep |min_height|min_height+colIStep|min_height+2colIstep|...| 
|min_weight + 2rowIstep|min_height|min_height+colIStep|min_height+2colIstep|...| 
|...| 

你在找什麼輸出?

+0

即時通訊基本上試圖做以下與列而不是行<?php $ iStep = 5; //獲得這些 $ iweightMin = $ _GET [「min_weight」]; $ iweightMax = $ _GET [「max_weight」]; $ iheightMin = $ _GET [「max_height」]; $ iheightmax = $ _GET [「min_height」]; $ iCur = $ iweightMin; $ iCol = $ iheightMin; print('

'); ('​​身高/
體重'); while($ iCur <= $ iweightMax) { printf('​​%d',$ iCur); $ iCur + = $ iStep; } \t ?> – jonn2013-03-14 22:28:00

+0

您是否介意編輯原始問題以包含您要查找的輸出和示例? – 2013-03-15 15:27:34