您好,我是PHP的初学者。
我有一个Mysql表这个
County | CCode
--------------- | ------
USA | USD
Euro | EUR
United Kingdom | UK
Australia | AUD
Japan | JPY
Canada | CAD
我希望使用PHP代码
这样的结果<table border = 1 width = "1200px" style="background-color:#FFCE4B;">
<tr>
<th class = "font-heading-currency">County</th>
<th class = "font-heading-currency">CCode</th>
</tr>
<tr>
<td>
<span class = "ctryname">USA</span>
<span class = "ctryname">Euro</span>
</td>
<td>
<span class="back">USD</span>
<span class="front">EUR</span>
</td>
</tr>
<tr>
<td>
<span class = "ctryname">United Kingdom</span>
<span class = "ctryname">Australia</span>
</td>
<td>
<span class="back">UK</span>
<span class="front">AUD</span>
</td>
</tr>
<tr>
<td>
<span class = "ctryname">Japan</span>
<span class = "ctryname">Canada</span>
</td>
<td>
<span class="back">JPY</span>
<span class="front">CAD</span>
</td>
</tr>
</table>
任何人都可以帮忙为此编写代码吗? 我对此一无所知。
答案 0 :(得分:1)
我认为您希望得到以下答案。
<?php
$query ="SELECT * From array_test" ;
//echo $query;
$resultset = mysqli_query($GLOBALS['con'], $query);
if( !$resultset ){
die('Error: ' . mysqli_error($GLOBALS['con']));
}
$rowcount=mysqli_num_rows($resultset);
$var1 = array();
$var2 = array();
while($result = mysqli_fetch_array($resultset)){
$var1[] = $result["Country"];
$var2[] = $result["ccode"];
}
echo '<table border = 1 width = "1200px" style="background-color:#FFCE4B;">
<tr>
<th class = "font-heading-currency">County</th>
<th class = "font-heading-currency">CCode</th>
</tr>';
$i= $rowcount/2;
$j=0;
while($i>0)
{
echo '<tr>
<td>
<span class = "ctryname">'.$var1[$j].'</span>
<span class = "ctryname">'.$var1[$j+1].'</span>
</td>
<td>
<span class="back">'.$var2[$j].'</span>
<span class="front">'.$var2[$j+1].'</span>
</td>
</tr>';
$j= $j+2;
$i--;
}
echo "</table>";
?>