0

我有通过数组检索表,现在我想根据用户输入在其他表中显示该数组,例如如果用户输入 2,那么如果用户输入 3 三 3 表,则只会出现 2 种类型的表以及表的数据带计算数据显示

表检索代码

<?php
include('config.php');
$sa="select * from table1 where c13='$d'";
$result=mysql_query($sa) or die(mysql_error());
echo "<table border='1'>
<tr>

</tr>";


 $row_count=0;
while($row = mysql_fetch_array($result)) 
{ 
    echo $row['c1'];
    echo $row['c2'];
    echo $row['c3'];
    echo $row['c4'];
$a[]=$row['c1'];
        $b[]=$row['c2'];
            $c[]=$row['c3'];
            $d[]=$row['c4'];
$m[]=round(($row['c1']/$row['c4']),2);
                $n[]=round(($row['c2']/$row['c4']),2);
                $o[]=round(($row['c3']/$row['c4']),2);
$row_count++;
 }
echo "Measuring table";
for($i=0;$i<$row_count;$i++) 
{ // do the exploding, the imploding, the row echoing for each row// 
echo "<table border='1' align='center'>
<tr>
<th>Inputs</th>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>";
  echo "<tr>";

     $f=implode($m,',');
     $r=explode(',',$f);
     print_r($f);
     $f1=implode($n,',');
     $r1=explode(',',$f1);
     print_r($f1);
     $f2=implode($o,',');
     $r2=explode(',',$f2);
     print_r($f2);
echo "<td>" ."W". "</td>";
echo "<td>".$r['0']. "</td>";

 echo "</tr>"; 
echo  "<td>" ."N". "</td>";
echo "<td>".$r1['$i']. "</td>";

 echo "</tr>"; 
echo  "<td>" ."D"."</td>";
echo "<td>".$r2['$i']. "</td>";

 echo "</tr>"; 
 echo "<td>" ."W". "</td>";
echo "<td>".$r['$i']. "</td>";

 echo "</tr>"; 
echo  "<td>" ."N". "</td>";
echo "<td>".$r1['$i']. "</td>";

 echo "</tr>"; 
echo  "<td>" ."D"."</td>";
echo "<td>".$r2['$i']. "</td>";

 echo "</tr>"; 
 </tables>

与其明确提及数组索引,不如像这样动态显示结果

c13=2(user enter value)
row1 2 3 4 
row2 4 6 7

检索后

        a       
w       2  
n       3
d       4    // this is of index 0//
w       4
n       6
d       7    // this is of index 1//

如果现在用户输入 3,数据库中将有 3 行。

检索后

w
n
d
w
n
d
w
n
d

我怎样才能动态地做到这一点?

我希望根据用户输入动态显示测量表。请帮我

4

1 回答 1

1

就在开始检索行的 while 循环之前,声明一个计数器变量。

$row_count = 0;
while {
    // loop here
    $row_count++;
}

在行检索结束时, $row_count 将保存...以及行数

** 编辑 ** 要正确回显测量表,您应该在 for 循环中构建您的代码

echo "Measuring table";
echo "<table border='1' align='center'>
<tr>
<th>Inputs</th>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>";
for($i=0;$i<$row_count;$i++) {
    echo "<tr>";
    $f=implode($m,',');
    $r=explode(',',$f);
    print_r($f);
    $f1=implode($n,',');
    $r1=explode(',',$f1);
    print_r($f1);
    $f2=implode($o,',');
    $r2=explode(',',$f2);
    print_r($f2);
    echo "<td>" ."W". "</td>";
    echo "<td>".$r[$i]. "</td>";

    echo "</tr>"; 
    echo  "<td>" ."N". "</td>";
    echo "<td>".$r1[$i]. "</td>";

    echo "</tr>"; 
    echo  "<td>" ."D"."</td>";
    echo "<td>".$r2[$i]. "</td>";

    echo "</tr>"; 
}
于 2013-05-28T08:08:38.097 回答