なぜmysqli_fetch_assocが5つではなく1つの結果しか表示しないのか分かりません。私はデータベースをチェックして倍増し、確かに5つのエントリがあります..mysqli_fetch_assocがすべての結果を表示していません
2番目のmysqli_fetch_assocを削除した場合、すべての結果が表示されます。
ご注意:接続が上記で含ま..
を何かアドバイスや提案は大歓迎されます...ありがとうございます!
<table class="table table-bordered table-hover">
thead>
<tr>
<th>Id</th>
<th>Author</th>
<th>Title</th>
<th>Category</th>
<th>Status</th>
<th>Image</th>
<th>Tags</th>
<th>Comments</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
if(isset($_GET['delete'])){
$post_id = $_GET['delete'];
$query = "DELETE FROM posts WHERE post_id='$post_id'";
$delete_post_query = mysqli_query($con, $query);
}
$query = mysqli_query($con, "SELECT * FROM posts");
while($row = mysqli_fetch_assoc($query)) {
$post_id = $row['post_id'];
$post_category_id = $row['post_category_id'];
$post_title = $row['post_title'];
$post_author = $row['post_author'];
$post_status = $row['post_status'];
$post_image = $row['post_image'];
$post_content = $row['post_content'];
$post_tags = $row['post_tags'];
$post_comment_count = $row['post_comment_count'];
$post_date = $row['post_date'];
echo "<tr>";
echo "<td>$post_id</td>";
echo "<td>$post_author</td>";
echo "<td>$post_title</td>";
$query = mysqli_query($con, "SELECT * FROM categories WHERE cat_id='$post_category_id'");
while($row = mysqli_fetch_assoc($query)) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<td>$cat_title</td>";
}
echo "<td>$post_status</td>";
echo "<td><img src='../images/$post_image' alt='image' width='100'></td>";
echo "<td>$post_tags</td>";
echo "<td>$post_comment_count</td>";
echo "<td>$post_date</td>";
echo "<td><a href='posts.php?delete=$post_id'>Delete</a></td>";
echo "<td><a href='posts.php?source=edit_post&p_id=$post_id'>Edit</a></td>";
echo "</tr>";
}
?>
</tr>
</tbody>
</table>
**危険**:あなたは** [SQLインジェクション攻撃](http://bobby-tables.com/)**に脆弱です**あなたは[守る]必要があります(http://stackoverflow.com/あなた自身から/ 60174/best-way-to-prevent-sql-injection-in-php) – Quentin
私は知っている...!最後にすべてのセキュリティ上の問題を修正します。 –
**決して** GETリクエストでレコードを削除しないでください。 https://thedailywtf.com/articles/WellIntentioned-Destruction – Phil