我有一个数据库名Accounts
的表,其中我有很多行和很多列,我想在我的html表中显示一列Account
(所有值)。我尝试了很多方法来显示特定的列值,而不使用php
的html中的索引,而我使用的是MySql
。
$storeArray = Array();
while($rowval = mysql_fetch_array($whole, MYSQL_ASSOC))
{
$storeArray[] = $rowval['Account'];
$status= $rowval['status'];
$ph1= $rowval['Phone1'];
$ph2= $rowval['Phone2'];
}
在<?php echo $storeArray[0]; ?>
中使用<?php echo $storeArray[1]; ?>
和<td>
我得到了解决方案。我的问题是,它会自动显示所有值而不提供任何index
?
答案 0 :(得分:4)
$conn=new mysqli("localhost","root","","your_db");
$rows=$conn->query("select username from User");
echo "<table border='1'>";
echo "<tr><th>Username</th></tr>";
while(list($username)=$rows->fetch_row()){
echo "<tr><td>$username</td></tr>";
}
echo "</table>";
答案 1 :(得分:1)
这是一个非常复杂的问题。我认为我能做的最好的事情就是指出你正确的方向。在w3schools.com上有一个很好的教程。你至少应该阅读这些:
也许
答案 2 :(得分:1)
**file user.php**
<?php
$conn=new mysqli("localhost","root","","your_db");
$rows=$conn->query("select id,username from User");
echo "<table border='1'>";
echo "<tr><th>Username</th></tr>";
while(list($id,$username)=$rows->fetch_row()){
echo "<tr>";
echo "<td>";
echo "<form action='user_details.php' target='_blank' method='post'>";
echo "<input type='hidden' name='txtId' value='$id' />";
echo "$id - $username";
echo "<input type='submit' name='btnView' value='View' />";
echo "</form>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
**file user_details.php**
<?php
if(isset($_POST["btnView"])){
$id=$_POST["txtId"];
$conn=new mysqli("localhost","root","","your_db");
$row=$conn->query("select id,username,email,phone from User where id='$id'");
list($id,$username,$email,$phone)=$row->fetch_row();
echo $id," ",$username," ",$email," ",$phone;
}
?>
答案 3 :(得分:1)
如果要在html表列中获取多个数据库列。
$conn=new mysqli("localhost","root","","your_db");
$rows=$conn->query("select col1,col2 from Tablename");
echo "<table border='1'>";
echo "<tr><th>col1</th><th>col2</th></tr>";
while(list($col1, $col2)=$rows->fetch_row())
{
echo "<tr><td>$col1</td><td>$col2</tr>";
}
echo "</table>";