gpt4 book ai didi

php - mysql_fetch_assoc "or die"语句已触发但仍在工作

转载 作者:行者123 更新时间:2023-11-29 06:12:55 26 4
gpt4 key购买 nike

如果这是一个愚蠢的问题,请原谅我。我才开始编程一周...

我在第 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com