Closed. This question is
off-topic。它目前不接受答案。
想改进这个问题吗?
Update the question所以堆栈溢出的值小于aa>。
去年关门了。
我正在为餐厅开发网上点菜系统。我想在本地主机中首次加载网页时显示产品详细信息。我已经将产品列表存储在数据库中,但问题是当我运行应用程序时,它显示以下两个错误。
警告:mysqli_num_rows()期望参数1是mysqli_result,
给定的对象
C:\ wamp64\www\onlineordering\functions\datafetching.php第15行
可捕获的致命错误:mysqli\u result类的对象不能是
转换为字符串
C:\ wamp64\www\onlineordering\functions\datafetching.php第87行
这是我的connection.php代码。
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "ecom1";
// Create connection
$con = mysqli_connect($servername, $username, $password,$db);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
?>
这是datafecthing.php的代码。
<?php
include "db/connection.php";
function getrecords($exePro,$msg,$con)
{
$counPro=mysqli_num_rows($exePro);
if($counPro>0)
{
$classPro=1;
while($resPro = mysqli_fetch_array($exePro))
{
$productcode= $resPro["productcode"];
$auto_number= $resPro["auto_number"];
$productname= $resPro["productname"];
$price= $resPro["price"];
//setlocale(LC_MONETARY,"en_US");
$price = $price;
$show_price= $resPro["show_price"];
$discount = (($show_price-$price)*100)/$show_price;
$img = "defualt.jpg";
$sql = "select * from productsimage where productanum='$auto_number' and size_type='s'";
$exeimg = mysqli_query($con,$sql)or die(mysql_error());
if(mysqli_num_rows($exeimg))
{
$resimg = mysqli_fetch_array($exeimg);
$img = $resimg['imagename'];
}
if($classPro%3==0)
{
$lastclass='no_margin_right';
}else{
$lastclass='';
}
?>
<div class="product_box <?php echo $lastclass;?>" >
<form method="post" action="productdetail.php" id="frmdetail<?php echo $classPro;?>">
<input type="hidden" name="productname" value="<?php echo $productname?>">
<input type="hidden" name="pid" value="<?php echo $productcode?>">
<input type="hidden" name="id" value="<?php echo $auto_number?>">
</form>
<img src="productimages/<?php echo $img?>" alt="Image
<?php echo $classPro;?>" style="height:150px;width:200px;cursor:pointer;" onclick="subform('frmdetail<?php echo $classPro;?>')"; />
<h3><?php echo $productname;?></h3>
<p class="product_price"><span style="text-decoration:line-through;"><?php echo currency.$show_price?></span><br/>
<?php echo currency.$price;?>
</p>
<form method="post" action="shoppingcart.php" id="frmaddproduct<?php echo $classPro;?>">
<input type="hidden" name="product_code" value="<?php echo $productcode?>">
<input type="hidden" name="product_qty" value="1">
<input type="hidden" name="type" value="add">
<input type="hidden" name="pid" value="<?php echo $auto_number;?>">
<input type="hidden" name="return_url" value="<?php echo $current_url;?>">
</form>
<a style="cursor:pointer;" onclick="subform('frmaddproduct<?php echo $classPro;?>')" class="add_to_card">Add to Cart</a>
<a style="cursor:pointer;" onclick="subform('frmdetail<?php echo $classPro;?>')" class="detail">Detail</a>
</div>
<?php
$classPro++;
}
}else{
//echo "Product is not available";
echo $msg;
}
}
?>
下面是要调用getrecords方法的index.php代码。
<?php
include "db/connection.php";
include "functions/datafetching.php";
?>
<!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>Codex King</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ddsmoothmenu.js">
</script>
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "top_nav", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<link rel="stylesheet" type="text/css" media="all" href="css/jquery.dualSlider.0.2.css" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript">
</script>
<script src="js/jquery.easing.1.3.js" type="text/javascript">
</script>
<script src="js/jquery.timers-1.2.js" type="text/javascript">
</script>
<script src="js/jquery.dualSlider.0.3.min.js" type="text/javascript">
</script>
<script type="text/javascript">
$(document).ready(function() {
$(".carousel").dualSlider({
auto:true,
autoDelay: 6000,
easingCarousel: "swing",
easingDetails: "easeOutBack",
durationCarousel: 1000,
durationDetails: 600
});
});
</script>
</head>
<body>
<div id="templatemo_wrapper">
<!--header -->
<?php include "include/header.php"; ?>
<!--menu-->
<?php include "include/menu.php"; ?>
<!--slider-->
<?php include "include/slider.php"; ?>
<div id="templatemo_main">
<div id="sidebar" class="float_l">
<!--category-->
<?php include "include/category.php";?>
<!--offerproduct-->
<?php include "include/offerproduct.php"; ?>
</div>
<div id="content" class="float_r">
<h1>Products</h1>
<?php
$sqlPro= "select * from products where recordstatus='' and is_home='yes'";
$exePro = mysqli_query($con,$sqlPro) or die ("Error in:sqlCat");
getrecords($con,$exePro,"Product is not available");
?>
</div>
<div class="cleaner">
</div>
</div> <!-- END of templatemo_main -->
<!-- footer.php -->
<?php include "include/footer.php"; ?>
</div> <!-- END of templatemo_wrapper -->
</body>
</html>
这里是productcategory.php代码。
<?php
include "db/connection.php";
include "functions/datafetching.php";
if(isset($_REQUEST['categoryid']))
$categoryid=trim($_REQUEST['categoryid']);
else
$categoryid='';
if($categoryid=='')
header('Location:index.php');
$sql = "select * from category where auto_number='$categoryid' and recordstatus=''";
$exe11= mysqli_query($con,$sql) or die("Exe11 error");
if(mysqli_num_rows($exe11)>0)
{
$res11 = mysqli_fetch_array($exe11);
$category = $res11['categoryname'];
}else {
header('Location:index.php');
}
?>
<!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>Codex King</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<script type="text/javascript" src="js/jquery.min.js">
</script>
<script type="text/javascript" src="js/ddsmoothmenu.js">
</script>
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "top_nav",
//menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu',
//class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup"
//"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<link rel="stylesheet" type="text/css" media="all" href="css/jquery.dualSlider.0.2.css" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript">
</script>
<script src="js/jquery.easing.1.3.js" type="text/javascript">
</script>
<script src="js/jquery.timers-1.2.js" type="text/javascript">
</script>
<script src="js/jquery.dualSlider.0.3.min.js" type="text/javascript">
</script>
<script type="text/javascript">
$(document).ready(function() {
$(".carousel").dualSlider({
auto:true,
autoDelay: 6000,
easingCarousel: "swing",
easingDetails: "easeOutBack",
durationCarousel: 1000,
durationDetails: 600
});
});
</script>
</head>
<body>
<div id="templatemo_wrapper">
<!--header -->
<?php include "include/header.php"; ?>
<!--menu-->
<?php include "include/menu.php"; ?>
<!--slider-->
<?php //include "include/slider.php"; ?>
<div id="templatemo_main">
<div id="sidebar" class="float_l">
<!--category-->
<?php include "include/category.php";?>
<!--offerproduct-->
<?php include "include/offerproduct.php"; ?>
</div>
<div id="content" class="float_r">
<h1><?php echo $category; ?></h1>
<?php
$sqlPro= "select * from products where recordstatus='' and categoryanum='$categoryid'";
$exePro = mysqli_query($con,$sqlPro) or die ("Error in:sqlCat");
getrecords($con,$exePro,"Product of this category is not available");
?>
</div>
<div class="cleaner">
</div>
</div> <!-- END of templatemo_main -->
<!-- footer.php -->
<?php include "include/footer.php"; ?>
</div> <!-- END of templatemo_wrapper -->
</body>
</html>
下面是productsdetails.php代码。。
<?php
include "db/connection.php";
include "functions/datafetching.php";
if(isset($_REQUEST['productname']))
$productname = trim($_REQUEST['productname']);
else
$productname='';
if(isset($_REQUEST['pid']))
$pid = trim($_REQUEST['pid']);
else
$pid='';
if(isset($_REQUEST['id']))
$id = trim($_REQUEST['id']);
else
$id='';
if($productname=='' or $pid=='' or $id=='')
header('Location:index.php');
?>
<!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>codex king - <?php echo $productname;?></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<script type="text/javascript" src="js/jquery.min.js">
</script>
<script type="text/javascript" src="js/ddsmoothmenu.js">
</script>
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
<script type="text/javascript">
ddsmoothmenu.init
({
mainmenuid: "top_nav",
//menu DIV id
orientation: 'h',
//Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu',
//class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<link rel="stylesheet" type="text/css" media="all" href="css/jquery.dualSlider.0.2.css" />
<script src="js/jquery-1.3.2.min.js" type="text/javascript">
</script>
<script src="js/jquery.easing.1.3.js" type="text/javascript">
</script>
<script src="js/jquery.timers-1.2.js" type="text/javascript">
</script>
<script src="js/jquery.dualSlider.0.3.min.js" type="text/javascript">
</script>
<script type="text/javascript">
$(document).ready(function() {
$(".carousel").dualSlider({
auto:true,
autoDelay: 6000,
easingCarousel: "swing",
easingDetails: "easeOutBack",
durationCarousel: 1000,
durationDetails: 600
});
});
</script>
</head>
<body>
<div id="templatemo_wrapper">
<!--header -->
<?php include "include/header.php"; ?>
<!--menu-->
<?php include "include/menu.php"; ?>
<!--slider-->
<?php //include "include/slider.php"; ?>
<div id="templatemo_main">
<div id="sidebar" class="float_l">
<!--category-->
<?php include "include/category.php";?>
<!--offerproduct-->
<?php include "include/offerproduct.php"; ?>
</div>
<div id="content" class="float_r">
<h1><?php echo $_REQUEST['productname']; ?></h1>
<?php
$sql = "select * from products where productcode='$pid'";
$exeprodet= mysqli_query($con,$sql) or die("Product Not available");
$res = mysqli_fetch_array($exeprodet);
$price=$res['price'];
$productcode = $res['productcode'];
$manufacturer=$res['manufacturer'];
$product_description = $res['product_description'];
$show_price = $res['show_price'];
$categoryanum = $res['categoryanum'];
$categoryid = $res['categoryid'];
$discount = (($show_price-$price)*100)/$show_price;
$discount = number_format($discount,2);
$sql = "select *
from productsimage
where product_id ='$pid' and size_type='l'";
$exeproimg= mysqli_query($con,$sql) or die("Product Not available");
$res1 = mysqli_fetch_array($exeproimg);
$img = $res1['imagename'];
?>
<div class="content_half float_l">
<a rel="lightbox[portfolio]" href="productimages/<?php echo $img;?>">
<img src="productimages/<?php echo $img;?>" style="height:200px; width:300px;" alt="Image 01" /></a>
</div>
<div class="content_half float_r">
<table>
<tr>
<td height="30" width="160">Price:</td>
<td><?php echo currency.$price;?></td>
</tr>
<tr>
<td height="30">Original Price:</td>
<td>
<span style="text-decoration:line-through;"><?php echo currency.$show_price?></span></td>
</tr>
<tr>
<td height="30">Discount:</td>
<td> <?php echo $discount."%";?></td>
</tr>
<tr>
<td height="30">Manufacturer:</td>
<td><?php echo $res['manufacturer'];?></td>
</tr>
<tr><td height="30">Quantity</td><td>
<script type="text/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
function checkqun(qun)
{
//var qun = document.getElementById(qunid);
var x = qun.value.trim();
if(x==0 || x=='' || isNaN(x))
{ alert("Please enter minimum Quntity is 1\n and It is only a number");
qun.value=qun.defaultValue;
return false;
}else
{
return true;
}
}
</script>
<form method="post" action="shoppingcart.php" id="frmaddproductrel">
<input type="hidden" name="product_code" value="<?php echo $productcode?>">
<input type="hidden" name="type" value="add">
<input type="hidden" name="pid" value="<?php echo $auto_number;?>">
<input type="hidden" name="external" value="sept">
<input type="hidden" name="return_url" value="<?php echo $current_url;?>">
<input type="text" value="1" onblur="checkqun(this)" name="product_qty" style="width: 20px; text-align: right" maxlength="2" onKeyPress="return isNumberKey(event)" />
</form>
</td></tr>
</table>
<div class="cleaner h20"></div>
<div class="product_box">
<a style="cursor:pointer;" onclick="subform('frmaddproductrel')" class="add_to_card">Add to Cart</a>
</div>
</div>
<div class="cleaner h30"></div>
<h4> <strong>Product Description </strong></h4>
<div style="background:#FFFFFF;padding:10px;">
<?php echo $product_description;?>
</div>
<div class="cleaner h50"></div>
<?php
$sqlPro= "select * from products where recordstatus='' and categoryanum='$categoryanum' and productcode <> '$productcode'";
$exePro = mysqli_query($con,$sqlPro) or die ("Error in:sqlCat");
$counPro= mysqli_num_rows($exePro);
if($counPro>0)
{
?>
<h4><strong>Related Product</strong></h4>
<?php
$classPro=1;
while($resPro = mysqli_fetch_array($exePro))
{
$productcode= $resPro["productcode"];
$auto_number= $resPro["auto_number"];
$productname= $resPro["productname"];
$price= $resPro["price"];
//setlocale(LC_MONETARY,"en_US");
$price = $price;
$show_price= $resPro["show_price"];
$discount = (($show_price-$price)*100)/$show_price;
$img = "defualt.jpg";
$sql = "select * from productsimage where productanum='$auto_number' and size_type='s'";
$exeimg = mysqli_query($con,$sql) or die("Sql Image Error");
if(mysqli_num_rows($exeimg)>0)
{
$resimg = mysqli_fetch_array($exeimg);
$img = $resimg['imagename'];
}
if($classPro%3==0)
{
$lastclass='no_margin_right';
}else{
$lastclass='';
}
?>
<form method="post" action="productdetail.php" id="frmdetailrel<?php echo $classPro;?>">
<input type="hidden" name="productname" value="<?php echo $productname?>">
<input type="hidden" name="pid" value="<?php echo $productcode?>">
<input type="hidden" name="id" value="<?php echo $auto_number?>">
</form>
<div class="product_box <?php echo $lastclass;?>" >
<img src="productimages/<?php echo $img?>" alt="Image <?php echo $classPro;?>"
style="height:150px;width:200px;cursor:pointer;" onclick="subform('frmdetailrel<?php echo $classPro;?>')" />
<h3><?php echo $productname;?></h3>
<p class="product_price"><span style="text-decoration:line-through;"><?php echo currency.$show_price?></span><br/>
<?php echo currency.$price;?>
</p>
<form method="post" action="shoppingcart.php" id="frmaddproductrel<?php echo $classPro;?>">
<input type="hidden" name="product_code" value="<?php echo $productcode?>">
<input type="hidden" name="product_qty" value="1">
<input type="hidden" name="type" value="add">
<input type="hidden" name="pid" value="<?php echo $auto_number;?>">
<input type="hidden" name="return_url" value="<?php echo $current_url;?>">
</form>
<a style="cursor:pointer;" onclick="subform('frmaddproductrel<?php echo $classPro;?>')" class="add_to_card">Add to Cart</a>
<a
onclick="subform('frmdetailrel<?php echo $classPro;?>')" style="cursor:pointer;" class="detail">Detail</a>
</div>
<?php
$classPro++;
}
}
?>
</div>
<div class="cleaner"></div>
</div> <!-- END of templatemo_main -->
<!-- footer.php -->
<?php include "include/footer.php"; ?>
</div> <!-- END of templatemo_wrapper -->
</body>
</html>
这是我运行应用程序时的屏幕截图。
on-topic
您的函数原型具有以下顺序的参数
function getrecords($exePro,$msg,$con)
但是当你调用这个函数时,你以错误的顺序显示参数,比如
getrecords($con,$exePro,"Product is not available");
如果对参数重新排序正确,它可能会工作,如下所示
getrecords($exePro,"Product is not available", $con);
或者您可以更改原型以匹配您如何调用函数!
我是一名优秀的程序员,十分优秀!