首页 \ 问答 \ 错误“mysqli_num_rows”[重复](Error “mysqli_num_rows” [duplicate])

错误“mysqli_num_rows”[重复](Error “mysqli_num_rows” [duplicate])

我该如何解决这个错误?

edit.php:

					<?php
   include 'connect.php';

   if(isset($_POST['btn_submit'])){
	
   }
   $cpf = '';
   $nome = '';
   $cep = '';
   if(isset($_GET['cpf'])){
	$sql = "select cpf, nome, cep from pessoas
		where cpf=" .$_GET['cpf'];
	$result = mysqli_query($con, $sql);
	if(mysqli_num_rows($result) > 0){
		$row = mysqli_fetch_assoc($result) ;
		$cpf = $row['cpf'];
		echo $cpf;
	}
   }
	
?>

错误:

Warning: mysqli_num_rows() expects parameter 1 to be 
mysqli_result, boolean given in 
C:\xampp\htdocs\Banco_de_dados\edit.php on line 158

Connect.php:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "meubd";
// Create connection
$con = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($con->connect_error) {
	die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT nome, cpf, cep, rua, bairro, cidade, estado, ibge FROM pessoas";
$result = $con->query($sql);
?>


How do I fix this error ?

edit.php:

					<?php
   include 'connect.php';

   if(isset($_POST['btn_submit'])){
	
   }
   $cpf = '';
   $nome = '';
   $cep = '';
   if(isset($_GET['cpf'])){
	$sql = "select cpf, nome, cep from pessoas
		where cpf=" .$_GET['cpf'];
	$result = mysqli_query($con, $sql);
	if(mysqli_num_rows($result) > 0){
		$row = mysqli_fetch_assoc($result) ;
		$cpf = $row['cpf'];
		echo $cpf;
	}
   }
	
?>

ERROR:

Warning: mysqli_num_rows() expects parameter 1 to be 
mysqli_result, boolean given in 
C:\xampp\htdocs\Banco_de_dados\edit.php on line 158

Connect.php:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "meubd";
// Create connection
$con = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($con->connect_error) {
	die("Connection failed: " . $con->connect_error);
}
$sql = "SELECT nome, cpf, cep, rua, bairro, cidade, estado, ibge FROM pessoas";
$result = $con->query($sql);
?>


原文:https://stackoverflow.com/questions/37114152
更新时间:2023-09-16 10:09

最满意答案

不。调用命名函数会花费变量查找(如果不是全局则便宜)和函数调用。 将命名函数传递给另一个函数只需要一个变量查找。

下面是在方形免费shell中Chrome上运行的一些微基准测试。 用一粒盐来衡量所有基准。

(function () {
  function f() { }
  var a = [1, 2, 3, 4, 5, 6];
  var t0 = Date.now();
  for (var i = 100000; --i >= 0;) { a.map(f); }
  var t1 = Date.now();
  print(t1 - t0);
})() 

24

(function () {
  var a = [1, 2, 3, 4, 5, 6];
  var t0 = Date.now();
  for (var i = 100000; --i >= 0;) { a.map(function f() {}); }
  var t1 = Date.now();
  print(t1 - t0);
})() 

29

传递命名函数比传递匿名函数更快,因为每个循环条目都会重复实例化匿名函数。


No. Calling a named function costs a variable lookup (cheap if not global) and a function call. Passing a named function to another function costs just a variable lookup.

Below are some micro-benchmarks run on Chrome in the square free shell. Take all benchmarks with a grain of salt.

(function () {
  function f() { }
  var a = [1, 2, 3, 4, 5, 6];
  var t0 = Date.now();
  for (var i = 100000; --i >= 0;) { a.map(f); }
  var t1 = Date.now();
  print(t1 - t0);
})() 

24

(function () {
  var a = [1, 2, 3, 4, 5, 6];
  var t0 = Date.now();
  for (var i = 100000; --i >= 0;) { a.map(function f() {}); }
  var t1 = Date.now();
  print(t1 - t0);
})() 

29

Passing the named function is faster than passing the anonymous function possibly because the anonymous function is instantiated repeatedly per loop entry.

相关问答

更多
  • 好! 上述问题之一导致对预期行为的讨论,结果是覆盖LESS变量是正确的。 您的声明将覆盖CSS中相同范围内的每一个; LESS也是如此。 https://github.com/cloudhead/less.js/issues/297 像CSS一样,覆盖范围是使用LESS的一种预期方式。 Ok! One of the above issues led to a discussion of the intended behaviour, and it turns out that overriding LESS ...
  • 原因可能是,每次执行渲染时都会创建匿名函数,而命名函数则不会。 虽然这不是什么大问题,但它被认为是React社区中的整洁和良好的做法。 查看这篇精彩文章,了解更多主题https://medium.com/@rjun07a/binding-callbacks-in-react-components-9133c0b396c6 您可以尝试以下代码。 const array = [0, 1, 2, 3] class Example extends React.Component { // Method cu ...
  • 实际上,这是一种很好的做法,因为它避免了任何全局状态(即理想情况下,函数的行为仅取决于其参数)。 如果你有很多参数要通过这种方式传递,我会将它们一起分批在一个单独的对象(一个'环境'对象)中,但除此之外它完全没问题。 这样做可以给你很大的灵活性 - 如果你想要一个函数对不同的数据进行一次操作,你只需要传递不同的值,而不是改变全局状态,这可能会影响其他一切(没有这样的)全局副作用使得很容易并行化函数,即使这对JavaScript来说可能不那么重要)。 Actually, that's good practic ...
  • 不要直接调用下一步,而是使用doNext调用下面的函数:你的实际下一步stepData :你的参数加上执行时间限制,以毫秒为单位unDoThis :如果必须撤消刚刚完成的工作就要运行的函数 function nextStep(doNext, stepData, unDoThis) { 第一次,设置时间 if (!stepData.expireAt) { var currentDate = new Date(); stepData.expireAt = current ...
  • 多线程时会发生中间文件的一个问题。 如果客户端C1和C2由服务器进程S同时处理(可能或者没有分成单独的进程,使用的线程或任何并发系统......),当两者都尝试创建相同的中间文件时,可能会遇到奇怪的问题。 我相信Unix哲学中的一个是所有程序都应该充当过滤器,但这并不一定意味着在磁盘上创建文件,并且使用中间文件会导致我认为行为笨拙。 人们还应该将磁盘视为最后的手段,并且仅将其用于存储/检索在关闭计算机后应该可用的数据,甚至可以使用允许程序在只读介质上运行。 One problem with intermed ...
  • 为什么这是不好的做法? 命名空间本身是不好的,因为这是一个不必要的概念。 具有属性和方法的对象是可以接受的。 具有类似于“命名空间”的“模块”令牌也很好,但是含义是每个文件都有一个包含所有属性和方法的“模块”令牌。 这与“命名空间”不同,因为它只在单个文件中创建/更改,并且不作为全局令牌公开。 这个声明的范围是什么(Web应用程序/动态网站/静态网站等)? 所有ECMAScript,从不创建新的全局令牌 有什么选择? 而不是有命名空间,你应该支持多个“文件本地”令牌。 这意味着每个文件/“模块”应该封装在闭 ...
  • 至少它不是一个好习惯,你可以使用一个immediated调用函数表达式 : (function() { var x; var y; window.init = function(xValue, yValue) { x = xValue; y = yValue; } window.doWhateverYouWant = function() { console.log(x + y); } }()); 您可以使 ...
  • 你提到了匿名类型,这应该可以做到这一点: foreach (var i in new[] { new{Dude=john, Booze=beer, Food=nachos}, new{Dude=bob, Booze=cider, Food=chips} }) { if (i.Dude != designatedDriver) ...
  • 不。调用命名函数会花费变量查找(如果不是全局则便宜)和函数调用。 将命名函数传递给另一个函数只需要一个变量查找。 下面是在方形免费shell中Chrome上运行的一些微基准测试。 用一粒盐来衡量所有基准。 (function () { function f() { } var a = [1, 2, 3, 4, 5, 6]; var t0 = Date.now(); for (var i = 100000; --i >= 0;) { a.map(f); } var t1 = Date.no ...
  • 由于加载顺序和依赖性,在文章中包含JS是一个坏主意。 只有在您需要仅在该单个文章页面上的脚本并且您已经测试了它的行为(并且如果您不是编码器)时才这样做。 最好的方法是通过: JHtml::_('script', 'path_to_script/script.js', false, true); 如果你想要正确嵌入它而不是乱用PHP,你可以使用这样的东西: http : //extensions.joomla.org/extensions/core-enhancements/performance/scr ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。