Please forgive me if this is a dumb question. I’m only a week into programming…
I’m getting my fetch error “or die” statement triggered on line 87 (at least in my editor it is 87, not sure how it will show up here). The strange thing is that it still works. The variables on the next two lines are being set and echoed correctly. Any ideas on why this is occurring would be appreciated. Thanks.
<?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 functions only return false, which would trigger your die(), if something went wrong with the query: syntax error, not connection, permission denied, etc…
A query which returns no results is NOT an error condition, and will not trigger the
or die(). An empty result set is a perfectly valid result set.As well,
makes no sense whatsoever, as an assignment will always succeed (unless you run out of memory or something).