- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果这是一个愚蠢的问题,请原谅我。我才开始编程一周...
我在第 87 行触发了获取错误“or die”语句(至少在我的编辑器中是 87,不确定它会如何显示在此处)。奇怪的是它仍然有效。接下来两行的变量正在正确设置和回显。任何关于为什么会发生这种情况的想法将不胜感激。谢谢。
<?php
include 'header.php';
//$results_per_page=10;
//$count_results=mysql_query("SELECT COUNT('zipcodes') FROM jobposts");
//$page_results=$count_results;
//echo $count_results;
//if ($count_results%$results_per_page!=0)
//{
//$page_results+=1;
//}
/////// zip code search setup ///////////
$homezip=22102;
$radius=10;
$id=1;
$query="select longitude,latitude from zipcodes where zipcode='$homezip'";
$run_query=mysql_query($query) or die ("run query error");
$findzip2=mysql_fetch_array($run_query) or die ("test");
$homelong=$findzip2['longitude'] or die ("array error");
$homelat=$findzip2['latitude'] or die ("array error");
function calcDist($lat_A, $long_A, $lat_B, $long_B) {
$distance = sin(deg2rad($lat_A))
* sin(deg2rad($lat_B))
+ cos(deg2rad($lat_A))
* cos(deg2rad($lat_B))
* cos(deg2rad($long_A - $long_B));
$distance = (rad2deg(acos($distance))) * 69.09;
return $distance;
}
//////// end zip code search setup ////////////////
echo "<table border='1'>";
if (isset($_POST['search']))
{
$keywords=$_POST['keywords'];
$zipcode=$_POST['zipcode'];
if ($zipcode=="")
{
($zipcode_search="");
}
else
{
($zipcode_search=" and zipcode='$zipcode'");
}
if (!(isset($_POST['hidden'])))
{
$search = "select * from jobposts where description LIKE '%$keywords%' $zipcode_search";
$run_search=mysql_query($search) or die ("cannot run search");
//$zip_array=$main_array[''];
//echo count($zip_array)."<br>";
//echo $zip_array['zipcode'];
////store results in array
////pull zip codes out of array one at a time
////put the zip codes in the radius function - if statement
////if less than allowable radius - publish results
$count=0;
if (mysql_num_rows($run_search)>=1)
{
while ($query_rows=mysql_fetch_assoc($run_search))
{
$zip_array[$count]=($query_rows['zipcode']);
$zip_to_test=$zip_array[$count];
$testquery="select longitude,latitude from zipcodes where zipcode='$zip_to_test'";
$testrun_query=mysql_query($testquery) or die ("run query error");
$testfindzip2=mysql_fetch_assoc ($testrun_query) or die ("fetch error - testfindzip2");
$testlong=$testfindzip2['longitude'] or die ("array error");
$testlat=$testfindzip2['latitude'] or die ("array error");
$count++;
echo $testlong."<br>";
if (calcDist($homelat,$homelong,$testlat,$testlong)<$radius)
{
echo "<tr><td>".$query_rows['company']."</td><td>".$query_rows['zipcode']."</td></tr>";
}
}
}
else
{
echo "No results found.";
}
}
else
{
echo "Please submit search data before submitting.";
}
}
else
{
echo "Failed to submit search request.";
}
?>
最佳答案
mysql 函数仅返回 false,如果查询出现问题:语法错误、未连接、权限被拒绝等,这将触发您的 die()...
不返回结果的查询不是错误条件,并且不会触发或 die()
。空结果集是完全有效的结果集。
还有,
$var = $othervar or die();
毫无意义,因为分配总是会成功(除非你耗尽内存或其他什么)。
关于php - mysql_fetch_assoc "or die"语句已触发但仍在工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8197504/
这是在 MacOS 上通过自制软件安装了 PHP 8.1.10 ... 只是一个空白的 index.php 代码,只有这段代码...... 然后 .. 在我的浏览器中呈现以查看... Fatal
我相信所有这些(甚至是 die() 或 die(0))都是相同的。如果它们不相同,那么哪个更适合成功退出脚本?如果它们相同,是否有任何首选标准表明脚本成功完成?我倾向于使用 exit;. 编辑:所有答
在对项目中一个非常模糊的错误进行了一些认真的调试之后,我能够得到这个简短的代码。一个没有死亡的死亡调用。 该问题仅在调用 script.pl 时发生。如果直接调用Class_A,那么die调用就会成功
注意:我正在使用输出缓冲。它只是包含在 head() 和 foot() 函数中。 我使用以下模板在我当前的 PHP 项目中创建页面: 以下示例是否适合使用 die()?另外,如果有的话,这可能给
我想这样写: die "Error in file $0 line number $line_number_of_this_cmd_in_file \n"; 在我的 perl 脚本文件中。 有什么帮助
下面是我尝试执行的代码 $a=0; if($a==0){die print"zero"}; 我得到如下输出 1 at test.pl line 2 Zero 我想知道首先打印的 1 是什么,
我使用以下代码在 perl 中运行一个简单的文件测试: my $f1 = "$pre_file"; unless (-e $1) { print "\n Pre_check file does n
我目前正在制作一个注册页面。它包括密码散列和验证。当我使用“die”时,它会停止表单并显示错误。我想在同一页面上显示错误。 $_POST['username'] ); try
我总是在发出 die() 命令之前调用 mysqli_close()。 这很乏味,有时会被遗忘,但我想确定 die 命令是关闭所有 mysql 连接还是仍然保持打开状态? 我无法通过 PHP 检查,因
让 die() 存在于生产环境中是否被认为是不好的做法?刚好看到这篇文章http://www.phpfreaks.com/blog/or-die-must-die作者抨击在生产环境中使用这种东西的人。
当我刚开始学习 PHP 时,我会编写类似于这里的查询语句: mysql_query("SELECT * FROM `table`") or die(mysql_error()); 目前最好的方法是什么
有没有人在 Python 中使用类似的东西: def die(error_message): raise Exception(error_message) ... check_somethin
我正在使用以下行进行一个简单的系统调用,该调用有效: system ("mkdir -p Purged") or die "Failed to mkdir." ; 执行脚本确实会进行系统调用,我可以找
我有一个通过 die 引发异常的脚本.当我捕捉到异常时,我想输出没有附加位置信息的消息。 这个脚本: #! /usr/bin/perl -w use strict; eval { die "M
在Perl中,如果程序因错误退出,则可以编写$SIG{__DIE__}处理程序来执行代码。 bash是否提供类似的功能? 这是我要尝试的操作:我有一个bash脚本,该脚本创建一个新目录并调用几个命令,
自从我创建 HTA 代码以来,我一直使用 IE :( 我们需要将更改事件捕获在 中元素,但你猜怎么着,IE 不支持该事件。 所以我创造了一种模仿它的方法。与 单击时显示 略低于。那部分工作正常。问题
this => set_time_limit (), Die() 可以用来取消文件上传吗。 即当用户单击按钮时,set_time_limit () 函数将执行。 它会停止上传吗? 最佳答案 您最好使用
我正在开发一些项目。我想控制不同的错误。我知道在所有流行的框架和 php 项目中都有不同的异常。但我认为这不是必需的工作。如果发生错误,我们可以用我们的消息制作 die()。1. Exceptions
最近我参加了 Jeffrey Richter 的有关 .NET 的培训类(class)。他提到了一种编码策略“死亡很棒”。也就是说,即使在程序或事件循环的根部也不要编写“catch (Exceptio
假设我们的类中有以下代码: //class code TextBox t = new TextBox(); ListBox l = new ListBox(); 我们有两种可能的情况: 首先,我们将
我是一名优秀的程序员,十分优秀!