在表中存储SQL数据时重复标题中的标题

时间:2018-04-24 16:11:59

标签: php html sql

当尝试显示存在SQL数据的表时,表顶部的行正在重复,我不想发生这种情况!我知道这可能是一些愚蠢的事情,但我已经尝试了一段时间来解决这个问题并且无法解决。图像概述了我使用的代码和显示的输出

Output to the user

Code which was used.

5 个答案:

答案 0 :(得分:1)

之前写下第一个<tr></tr> 像这样:

echo "<table>";
echo "<tr>
<th>albul Name</th>
..
..
..
</tr>";
while($album=$stmt->fetchObject()) {
echo "<tr>
<td>$album->$album_name
...
...
</tr>";
}

答案 1 :(得分:1)

问题是你正在回显WHILE循环内的Header行,所以你要为循环的每次迭代编写头。

要修复,请将标题行移出循环,如下所示:

echo "<table><tr>
<th>album Name</th>
<th>Year</th>
<th>Genre</th>
<th>Artist Name</th>
<th>Total Running Time</th>
</tr>"
while ($album = $stmt->fetchObject()) {
//Display the data as a row.
    echo "<tr>
    <td>$album->album_name</td>
    <td>$album->year</td>
    <td>$album->genre</td>
    <td>$album->artist_name</td>
    <td>$album->total_time</td>
    </tr>"
}//end loop
echo "</table>";

答案 2 :(得分:0)

当你长时间看东西时,你再也看不到了。只需从while循环中取出标签即可。您只需要循环中的数据行。

答案 3 :(得分:0)

从WHILE循环中取出代码。

第一行,应该在循环代码开始之前

答案 4 :(得分:0)

你需要改变你的代码是firts设置你的strutsure html表和下一个php代码:

List<String> list = new ArrayList<>(jeproduto.keys("*"));

现在你需要从db

打印你的记录
<?php
$con = mysqli_connect("localhost","root","","system_database");
if(isset($_POST['Submit'])){
    $Username = trim($_POST['Username']);
    $password = trim($_POST['password']);
    if(!empty($Username) && !empty($password)){
        $Username = mysqli_real_escape_string($con,$Username);
        $password = mysqli_real_escape_string($con,$password);
        // encrypt password before submiting it
        $password_encrypted = crypt($password, 'is'); // "is" is the salt
        $sql = "SELECT * FROM register WHERE Username = '{$Username}' AND password='{$password_encrypted}'";
        if($result = mysqli_query($con,$sql)){
            if(mysqli_num_rows($result) > 0){
                mysqli_free_result($result);
                header("Location: report.php");         
            }else{
                echo "username or password wrong";
            }
        }
    }else{
        echo "username or password not found";
    }
}
?>

所有代码都是这样的:

<?php
echo"
    <table border="1">
    <tr>
      <td>ALBUM</td>
      <td>YEAR</td>
      <td>GENERE</td>
      <td>ARTIST</td>
      <td>TOTAL PLAYING TIME</td>
    </tr>
";