Php mysql_fetch_array()除参数1外
我试图在第一页使用select选项显示数据库中的一些数据 但当页面试图从数据库检索数据时,我遇到了两个错误 错误是Php mysql_fetch_array()除参数1外,php,html,mysql,database,fetch,Php,Html,Mysql,Database,Fetch,我试图在第一页使用select选项显示数据库中的一些数据 但当页面试图从数据库检索数据时,我遇到了两个错误 错误是 mysql_num_rows() expects parameter 1 to be resource, boolean given 及 这是我的密码 <?php //connect to server $connect = mysql_connect("localhost", "root", ""); //connect to database //select the
mysql_num_rows() expects parameter 1 to be resource, boolean given
及
这是我的密码
<?php
//connect to server
$connect = mysql_connect("localhost", "root", "");
//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";
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 WHERE applicant1_country='$country' FROM auip_wipo_sample";
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";
}
}
}
$result = mysql_query($sql);
$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='index.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='index.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>";
?>
及
我想我已经给出了这行的参数
$result = mysql_query($sql);
有人知道怎么解决这个问题吗
谢谢你试试这个
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE
applicant1_country='".$country."'";
首先不要使用mysql\u*使用mysqli\u*然后检查mysql\u num\u行($result)>0您没有在数据库连接或查询的任何位置执行任何错误检查。那是犯罪。这样做。
mysql\u查询($sql)如果查询失败,code>返回false。所以$result是假的!第一个SQL顺序是错误的从哪里选择
应该是从哪里选择
@Waygood谢谢老兄…我犯了一个愚蠢的错误…谢谢老兄
while($row = mysql_fetch_array($result))
$result = mysql_query($sql);
$sql = "SELECT wipo_applicant1_city, applicant1_addr1 FROM auip_wipo_sample WHERE
applicant1_country='".$country."'";