我想要这样的表数据,但是使用while
或for
循环动态获取数据。
<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>
这是我的表数据:
County | CCode
--------------- | ------
USA | USD
Euro | EUR
United Kingdom | UK
Australia | AUD
Japan | JPY
Canada | CAD
如何使用while
或for
循环动态获取数据。
任何人都可以帮忙吗?
答案 0 :(得分:0)
请不要使用MYSQL,使用MYSQLI或PDO准备好的声明!
这是一个适合您的mysqli解决方案。
$result = $MySQLi->query($sqlStr);
$data = [];
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$data[] = $row;
}
echo $data;
echo $data["fieldname"];