我正在尝试用各自的信息填充各种 html 选择。为此,我觉得正确的方法是对它们中的每一个进行查询。我使用此 php 标记执行第一个查询以填充第一个 select,如下所示:
<?php
$sql = "call mydb.getPositions();";
$result = $conn->query($sql);
while($row = $result->fetch_row()){
echo "<option>".$row[0]."</option>";
}
?>
就是这样。简单的。有用。 getPositions() 函数是一个select。但是当我试图用它自己的查询填充下一个选择/组合框时,它开始抛出这个错误:
Fatal error: Call to a member function fetch_row() on a non-object in file.php in line 200
我搜索了很多错误的原因,例如查询中的拼写错误或从 delete 查询中获取行。
但是为了排除其中的任何错误,我决定一个接一个地复制完全相同的 php 标签。那么,如果第一个有效,为什么第二个无效?所以我看到我收到了完全相同的错误。我错过了什么?我试图关闭 $result,但没有成功。
提前致谢。
编辑。 当我说“我决定一个接一个地复制完全相同的 php 标签”时,我的意思是这样的:
<?php
$sql = "call mydb.getPositions();";
$result = $conn->query($sql);
while($row = $result->fetch_row()){
echo "<option>".$row[0]."</option>";
}
?>
<?php
$sql = "call mydb.getPositions();";
$result = $conn->query($sql);
//It throws the error down here
while($row = $result->fetch_row()){
echo "<option>".$row[0]."</option>";
}
?>
这会引发与之前描述的相同的错误。
编辑2。 程序是这样的:
CREATE DEFINER=`mainSoccer`@`%` PROCEDURE `getPositions`()
BEGIN
Select namePosition from mydb.Position;
END
最佳答案
看起来您的问题实际上是:如何在 php 脚本中运行相同的 MySQL 查询两次?如果是,答案如下:
<?php
$sql = "Select namePosition from mydb.Position;";
$result = $conn->query($sql);
while($row = $result->fetch_row()){
echo "<option>".$row[0]."</option>";
}
?>
<!-- presumably you have other code in between here -->
<?php
$sql = "Select namePosition from mydb.Position;";
$result = $conn->query($sql);
while($row = $result->fetch_row()){
echo "<option>".$row[0]."</option>";
}
?>
在您对下面我的原始回答的评论中,您问“我为什么不应该创建一个 MySQL 过程?”两个答案:
希望这对您有所帮助。
关于php - 在单个 php 上执行两个查询会导致无法获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33601404/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)