데이터베이스에서 특정 데이터를 정렬하려고했습니다. 첫 번째 페이지의 사용자 입력에 따라 특정 데이터를 표시했습니다. 나는 테이블을 정렬하려고 할 때 그러나, 나는 이것이 내가테이블의 특정 데이터 정렬
Undefined index: formSubmit in C:\xampp\htdocs\fak_ict1999\sorting\showDB1.php
Undefined variable: country in C:\xampp\htdocs\fak_ict1999\sorting\showDB1.php
Undefined variable: country in C:\xampp\htdocs\fak_ict1999\sorting\showDB1.php
Undefined variable: order in C:\xampp\htdocs\fak_ict1999\sorting\showDB1.php
Undefined variable: sort in C:\xampp\htdocs\fak_ict1999\sorting\showDB1.php
에 오류가있어
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "") or die('no database');
//connect to database
//select the database
mysql_select_db("fak_databases");
//submit button
if($_POST['formSubmit'] == "Submit")
{
$country = $_POST['country'];
}
//query the database
if($country == TRUE) {
$order = "";
$sort = "asc";
if(isset($_GET['orderby'])){
$order = $_GET['orderby'];
$sort = $_GET['sort'];
//limiting the possible values of order/sort variables
if($order != 'wipo_applicant1_city' && $order != 'applicant1_addr1')$order = "applicant1_addr1";
if($sort != 'asc' && $sort != 'desc')$sort = "asc";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE applicant1_country='$country' ORDER BY ".mysql_real_escape_string($order)." ".$sort;
//here we reverse the sort variable
if($sort == "asc"){
$sort = "desc";
}
else{
$sort = "asc";
}
}
}
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE applicant1_country='$country'";
$result = mysql_query($sql) or die('failed to run');
$num_rows = mysql_num_rows($result);
$row_counter = 0;
$icon = "";
echo "<table border=\"1\" cellspacing=\"0\">\n";
echo "<tr>\n";
// first column
echo "<th>";
$icon = "";
if($order == "wipo_applicant1_city"){
if($sort == "asc"){
$icon = "<img src=\"images/up.png\" class=\"arrowSpace\"/>";
}
if($sort == "desc"){
$icon = "<img src=\"images/down.png\" class=\"arrowSpace\"/>";
}
}
//print the result
echo "<a href='showDB1.php?orderby=wipo_applicant1_city&sort=".$sort."'>City</a>".$icon;
echo "</th>\n";
// second column
echo "<th>";
$icon = "";
if($order == "applicant1_addr1"){
if($sort == "asc"){
$icon = "<img src=\"images/up.png\" class=\"arrowSpace\"/>";
}
if($sort == "desc"){
$icon = "<img src=\"images/down.png\" class=\"arrowSpace\"/>";
}
}
echo "<a href='showDB1.php?orderby=applicant1_addr1&sort=".$sort."'>Address</a>".$icon;
echo "</th>\n";
echo "</tr>";
//fetch the result
while($row = mysql_fetch_array($result))
{
if($row_counter % 2){
$row_color="bgcolor='#FFFFFF'";
}else{
$row_color="bgcolor='#F3F6F8'";
}
echo "<tr class=\"TrColor\" ".$row_color.">";
echo "<td>" . $row['wipo_applicant1_city'] . "</td>\n";
echo "<td>" . $row['applicant1_addr1'] . "</td>\n";
echo "</tr>";
$row_counter++;
}
Print "</table>";
?>
테이블을 테이블에 데이터를 표시하고 정렬하는 내 코드입니다
변수 정의되지 않은 일부 오류가있어 내 코드를 분석 할 때
와 나는 내가
if($_POST['formSubmit'] == "Submit")
{
$country = $_POST['country'];
}
//query the database
if($country == TRUE) {
$order = "";
$sort = "asc";
if(isset($_GET['orderby'])){
$order = $_GET['orderby'];
$sort = $_GET['sort'];
//limiting the possible values of order/sort variables
if($order != 'wipo_applicant1_city' && $order != 'applicant1_addr1')$order = "applicant1_addr1";
if($sort != 'asc' && $sort != 'desc')$sort = "asc";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE applicant1_country='$country' ORDER BY ".mysql_real_escape_string($order)." ".$sort;
//here we reverse the sort variable
if($sort == "asc"){
$sort = "desc";
}
else{
$sort = "asc";
}
}
}
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE applicant1_country='$country'";
에 논리 오류를 가지고 생각할 때 I를하기 때문에 테이블을 정렬하려고하면 정렬 기능이 formubmit에 다시 액세스하려고합니다. 사용자가 옵션을 선택하면 양식 제출이 첫 페이지에서만 액세스됩니다.
누구든지 이것을 해결하는 방법을 알고 있습니까?
내 HTML 코드
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Data Mining</title>
</head>
<body>
<form action="showDB.php" method="post">
<table border="0">
<tr>
<th colspan="3">test</th>
</tr>
<tr>
<td>Select Foreign Agent Country</td>
<td></td>
<td>
<select name="country">
<option value="US">United States</option>
<option value="NZ">New Zealand</option>
<option value="JP">Japan</option>
</select>
</td>
</tr>
<td colspan="3">
<input type="submit" name="formSubmit" value="Submit">
</td>
</table>
</form>
</body>
</html>
여기 내 자바 스크립트 코드
function SelectAll(btn) {
var blnVal = false;
if (btn.value == "Select All") {
btn.value = "Unselect All";
blnVal = true;
}else {
btn.value = "Select All";
blnVal = false;
}
var d = document.forms["auip_wipo_sample"];
if(d["auip_wipo_sample[]"] == null)
{}
else if (d["auip_wipo_sample[]"].length == null) {
d["auip_wipo_sample[]"].checked = blnVal;
}
else {
for (var i = 0; i < d["auip_wipo_sample[]"].length; i++) {
d["auip_wipo_sample[]"][i].checked = blnVal;
}
}
}
$ _get [ 'sort']이 설정되어 있는지 확인하지 마십시오. – bestprogrammerintheworld
@bestprogrammerintheworld 실제로 자바 스크립트를 사용하여 테이블을 정렬하고 있습니다 ... 자바 스크립트를 사용한다면 $ _get [ 'sort']을 사용할 필요가 없습니다. –
실제 HTML 양식과 자바 스크립트 코드가 어떻게 보이나요? 처럼? – bestprogrammerintheworld