안녕하세요 여러분, 제가 만든이 스크립트에 문제가 있습니다. 검색 창을 사용하여 내 웹 사이트의 데이터를 테이블 형식으로 검색 할 때마다 첫 번째 행은 항상 데이터와 함께 완벽하게 반환되지만 첫 번째 행 이후의 모든 데이터는 다른 행에서 제자리를 벗어납니다. 나는 테이블이 아닌 구조 상황에서 완벽하게 할 수 있었기 때문에 이것이 왜 이러는지 모르겠다. 모든 데이터를 그대로 유지할 수있는 방법에 대한 도움이 필요하다.
<?php
//SEARCHX
include("hidden_path/mysqli/procedural/session/session_crud/v1/0/instructions/php/session_and_connection.php");
$output = ' ';
if(isset($_GET['search']) && $_GET['search'] !== ' ') {
$user_input = $_GET['search'];
if ($user_input === "") {
header('Location: '.$_SERVER['PHP_SELF']);
die;
}
//PAGINATION
$user_input = $_GET['search'];
$and = "&";
$pagevx = "page=";
//SEARCHX
$user_input = trim(" $user_input ");
$user_input = preg_replace('/\s+/', ' ', $user_input);
$user_input = mysqli_real_escape_string($connect, $user_input);
$user_input = htmlspecialchars($user_input);
//PAGINATION
$page = mysqli_query($connect, "SELECT COUNT(*) FROM posts WHERE post_title LIKE '%$user_input%' OR post_content LIKE '%$user_input%'");
// total row count
$row = mysqli_fetch_row($page);
$rows = $row[0];
// results displayed per page
$page_rows = 2;
// page number of last page
$last = ceil($rows/$page_rows);
// makes sure $last cannot be less than 1
if($last < 1) {
$last = 1;
}
// page num
$pagenum = 1;
// get pagenum from URL if it is present otherwise it is 1
if(isset($_GET['page'])) {
$pagenum = preg_replace('#[^0-9]#', '', $_GET['page']);
}
// makes sure the page number isn't below 1, or more then our $last page
if($pagenum < 1) {
$pagenum = 1;
}
else if($pagenum > $last) {
$pagenum = $last;
}
// set the rage of rows to query for the chosen $pagenum
$limit = 'LIMIT ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
$page = mysqli_query($connect, "SELECT * FROM posts WHERE post_title LIKE '%$user_input%' OR post_content LIKE '%$user_input%' ORDER BY post_id DESC $limit");
// establish $paginationCtrls variable
$paginationCtrls = '';
// if more the 1 page
if($last != 1) {
if($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<a href="'. $row["post_title"].'?search='.$user_input.$and.$pagevx.$previous.'"><span class="pag_back_arrow"; style="text-decoration: none;"><</a></span> ';
// Render clickable number links
for($i = $pagenum - 4; $i < $pagenum; $i++) {
if($i > 0) {
$paginationCtrls .= '<a href="'. $row["post_title"].'?search='.$user_input.$and.$pagevx.$i.'">'.$i.'</a> ';
}
}
}
// render the target page number without a link
$paginationCtrls .= ''. $pagenum . ' ';
// render clickable number links that appear on the right
for($i = $pagenum + 1; $i < $last; $i++) {
$paginationCtrls .= '<a href="'. $row["post_title"].'?search='.$user_input.$and.$pagevx.$i.'">'.$i.'</a> ';
// allows up to 4 pages
if($i >= $pagenum + 4) {
break;
}
}
if($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' <a href="'. $row["post_title"].'?search='.$user_input.$and.$pagevx.$next.'"><span class="pag_next_arrow"; style="text-decoration: none;">></a></span> ';
}
}
//SEARCHX
?>
<!DOCTYPE html>
<html>
<head>
<title>
Results
</title>
</head>
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="0/instructions/css/query/desktop.css">
<link rel="stylesheet" type="text/css" href="0/instructions/css/query/mobile.css">
<body>
<?php
//SEARCHX
$c = mysqli_num_rows($page);
if($c == 0) {
$output = '<h2 class="no_results_error_message";><span style="color: red;">No results for: </span><b><span style="color: white;">' . $user_input . '</span></h2></b>';
} else {
?>
<div class="result_section";>
<h2><span class="for_headline">Results For: </span><span id="result_output"><?php $outputx = "$user_input"; print("$outputx"); ?></span></h2>
</div>
<!-- Search Box -->
<?php include("search_box.php"); ?> <br>
<table width='80%' border=0>
<tr bgcolor='#CCCCCC'>
<td>user_id</td>
<td>topic_id</td>
<td>post_title</td>
<td>post_content</td>
<td>post_date</td>
<td>Update</td>
</tr>
<?php
// shows the user what page they are on, and the total number of pages
$textline1 = "Search_i";
$textline2 = "Page <b>$pagenum</b> of <b>$last</b>";
while($row = mysqli_fetch_array($page, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>".$row['user_id']."</td>";
echo "<td>".$row['topic_id']."</td>";
echo "<td>".$row['post_title']."</td>";
echo "<td>".$row['post_content']."</td>";
echo "<td>".$row['post_date']."</td>";
echo "<td><a href=\"edit.php?post_id=$row[post_id]\">Edit</a> | <a href=\"delete.php?post_id=$row[post_id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td></table>";
?>
<?php
$output .= '<a href="' . $link . '">
</a>';
}
}
} else {
header("location: ./");
}
print("$output");
mysqli_close($connect);
?>
<!-- PAGINATION -->
<!--shows the user what page they are on, and the total number of pages -->
<p><?php //echo $textline1 = "Search_i"; ?></p>
<p id="page_of";><?php //echo $textline2; ?></p>
<div class="pagination_controls"><?php echo $paginationCtrls; ?></div>
</body>
</html>
루프에서 테이블을 닫고 있습니다. 코드 변경
while ($row = mysqli_fetch_array($page, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['user_id'] . "</td>";
echo "<td>" . $row['topic_id'] . "</td>";
echo "<td>" . $row['post_title'] . "</td>";
echo "<td>" . $row['post_content'] . "</td>";
echo "<td>" . $row['post_date'] . "</td>";
echo "<td><a href=\"edit.php?post_id=$row[post_id]\">Edit</a> | <a href=\"delete.php?post_id=$row[post_id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td></tr>";
}
</table> //close table after loop
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다