正在将数据库中的数据插入 table。最后一列不工作
Inserting data from database into table. LAST COLUMN NOT WORKING
除了最后一个 table 数据(数据 7)没有插入并显示为空白外,我的代码工作正常。
<table id="History" class="table table-striped table-bordered" style="width:100%">
<a href="export.php"> Export To Excel </a>
<thead>
<tr>
<th>First <br> Name</th>
<th>Last <br> Name</th>
<th>Competition <br> Name</th>
<th>Competition Level</th>
<th>Dance Name</th>
<th>Number of Competitors</th>
<th>Dancer's Placement</th>
<th>Dancer's Score</th>
<th>1st Place Score</th>
</tr>
</thead>
<?php
$sql = "SELECT `dancer_name`,`dancer_lastname`,`comp_name`,`competition_level1`, `dance_name1`, `number_competitors1`, `dancer_placement1`, `dancer_score1`, `1stpl_score1` FROM `report` WHERE name = '$name'";
$res = mysqli_query($con,$sql);
//if($res==FALSE){
//die('there was an error running query [' . $con->error . ']');
// }
while($data=mysqli_fetch_row($res)){
echo '
<tr>
<td>'.$data[0].'</td>
<td>'.$data[1].'</td>
<td>'.$data[2].'</td>
<td>'.$data[3].'</td>
<td>'.$data[4].'</td>
<td>'.$data[5].'</td>
<td>'.$data[6].'</td>
<td>'.$data[7].'</td>
</tr>
';
}
?>
</table>
数据 0-6 显示正常,但 7 始终为空白。请告诉我,我的代码有什么问题?
我首先建议您使用php 函数var_dump($data) 来显示其中的内容。稍后您必须检查索引 7 [7] 是否为 null 或空,如果是,请检查您的 table 数据库以确保记录是否存在... 如果存在,请检查您的查询以确保属性是否正确。
这可能有帮助:
Bonus: I suggest you use mysqli_fetch_array instead mysqli_fetch_row, because you can "use associative indices, using the field names of the result set as keys", making your code more maintainable and legibility.
例如:
$data["dancer_name"]; // instead $data[0]
除了最后一个 table 数据(数据 7)没有插入并显示为空白外,我的代码工作正常。
<table id="History" class="table table-striped table-bordered" style="width:100%">
<a href="export.php"> Export To Excel </a>
<thead>
<tr>
<th>First <br> Name</th>
<th>Last <br> Name</th>
<th>Competition <br> Name</th>
<th>Competition Level</th>
<th>Dance Name</th>
<th>Number of Competitors</th>
<th>Dancer's Placement</th>
<th>Dancer's Score</th>
<th>1st Place Score</th>
</tr>
</thead>
<?php
$sql = "SELECT `dancer_name`,`dancer_lastname`,`comp_name`,`competition_level1`, `dance_name1`, `number_competitors1`, `dancer_placement1`, `dancer_score1`, `1stpl_score1` FROM `report` WHERE name = '$name'";
$res = mysqli_query($con,$sql);
//if($res==FALSE){
//die('there was an error running query [' . $con->error . ']');
// }
while($data=mysqli_fetch_row($res)){
echo '
<tr>
<td>'.$data[0].'</td>
<td>'.$data[1].'</td>
<td>'.$data[2].'</td>
<td>'.$data[3].'</td>
<td>'.$data[4].'</td>
<td>'.$data[5].'</td>
<td>'.$data[6].'</td>
<td>'.$data[7].'</td>
</tr>
';
}
?>
</table>
数据 0-6 显示正常,但 7 始终为空白。请告诉我,我的代码有什么问题?
我首先建议您使用php 函数var_dump($data) 来显示其中的内容。稍后您必须检查索引 7 [7] 是否为 null 或空,如果是,请检查您的 table 数据库以确保记录是否存在... 如果存在,请检查您的查询以确保属性是否正确。
这可能有帮助:
Bonus: I suggest you use mysqli_fetch_array instead mysqli_fetch_row, because you can "use associative indices, using the field names of the result set as keys", making your code more maintainable and legibility.
例如:
$data["dancer_name"]; // instead $data[0]