简单的问题, 我怎样才能使表在PHP中有两列和10个变量,例如(不循环)?PHP表两列
例如:
$var1= $row['name'];
$var2= $row['age'];
我想表明它在路表:
______________________
| Customer Name | $var1|
| Customer Age | $var2|
简单的问题, 我怎样才能使表在PHP中有两列和10个变量,例如(不循环)?PHP表两列
例如:
$var1= $row['name'];
$var2= $row['age'];
我想表明它在路表:
______________________
| Customer Name | $var1|
| Customer Age | $var2|
没有循环:
echo '
<table>
<tr>
<td>Customer Name</td>
<td>', $var1, '</td>
</tr>
<tr>
<td>Customer Age</td>
<td>', $var2, '</td>
</tr>
<tr>
<td>Customer ...</td>
<td>', $var3, '</td>
</tr>
</table>';
用foreach循环
$myFields = array("Customer Name" => $row['Name'],
"Customer Age" => $row['Age']);
echo '<table><tr>';
foreach($myFields as $field_title => $field_value)
echo '<td>', $field_title, '</td>
<td>', $field_value, '</td>';
echo '</tr></table>';
谢谢大家,这个工作的罚款:) – MahmoudMustafa
简单。使用此语法:
<table >
<tr>
<th>Customer Name</th>
<td><?php echo $var1; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var2; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var3; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var4; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var5; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var6; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var7; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var8; ?></td>
</tr>
<tr>
<th>Customer Name</th>
<td><?php echo $var9; ?></td>
</tr>
<tr>
<th>Customer Age</th>
<td><?php echo $var10; ?></td>
</tr>
</table>
您可以使用这样的事情:
$array = array();
$array[0]["name"];
$array[0]["age"];
或代替的,你可以使用一个循环:
$i=0;
while($i<10){
$array[$i]["name"]=...;
$i++;
}
print_r($array);
** NO LOOP !!!! ** –
所以它是如此简单的手工做,没有环... – 2012-10-31 07:46:41
蒙山出LOOP ....为什么你想试试! –