[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

php xajax if else statement

$found reutrns a value to the $myhtml variable.
when I run the statements below I dont get an error, just does not return any value for the $myhtml variable. Comes back blank.

My goal is to have the first $myhtml variable returned if no records are found. records are found then do the else.  Missing something agian.



$found = $result->getFoundSetCount();
 
if($found <1){
 
$myhtml = "No Records Found!. Select near the middle of a parcel to get information about that parcel.";
$objResponse = new xajaxResponse();
$objResponse->script("myhtml = '$myhtml';");
return $objResponse;
}
else{
 
$row = 0;
foreach ($records as $record) {
  $taxid = $record->getField('TAXID_11');
  $lat = $record->getField('LATNUM');
  $lon =  $record->getField('LONNUM');
  $sub = $record->getField('SUBDIVISIO');
  $blk = $record->getField('BLOCK');
  $lot = $record->getField('LOT');
  $fname = $record->getField('FIRST_NAME');
  $lname = $record->getField('LAST_NAME');
  $row++;
}
$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\\r\\n Legal: " . $sub . " " . $blk . " " . $lot . " \\r\\\nOwner: ".$fname . " " . $lname . "\\r\\nFound: " . $found;
$myhtml2 = " Count: ". $row . " Taxid: ". $taxid . "<br />Legal: " . $sub . " " . $blk . " " . $lot . "<br />Owner: ".$fname . " " . $lname . "<br />Found: " . $found;
 
$objResponse = new xajaxResponse();
$objResponse->script("blk = '$blk';sub = '$sub';fname = '$fname';lname = '$lname';taxid = '$taxid';lot = 'lot';myhtml = '$myhtml';;myhtml2 = '$myhtml2';");
 
return $objResponse;
 
}
}
?>

Open in new window

0
ALASKASTREETMASTER
Asked:
ALASKASTREETMASTER
  • 7
  • 4
1 Solution
 
Roger BaklundCommented:
It seems you have a backslash too much here:

" \\r\\\nOwner: "

...it should be just:

" \\r\\nOwner: "
0
 
ALASKASTREETMASTERAuthor Commented:
that fixed the blank info in the popup.  But when I click on a place on the map, like a road, where there is no info, it should find 0 records. What is happening is it is showing the popup from the previous good selection. In other words, if you click on a road a bunch of times it will keep showing you the info from the last property that it found info for. It should be displaying the no info found popup.

thanks again!
<?php
 
require_once("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->configure( 'defaultMode', 'synchronous' );
$xajax->configure('javascript URI','xajax/');
$xajax->registerFunction("getll");
$xajax->processRequest();
 
function getll($lonquery,$latquery){
require_once("FileMaker.php");
$fm = new FileMaker('Cama');
$fm->setProperty('username', 'Admin');
$fm->setProperty('password', 'john');
$findCommand =& $fm->newFindCommand('ASM');
$findCommand->addFindCriterion('LONNUM',$lonquery);
$findCommand->addFindCriterion('LATNUM',$latquery);
$result = $findCommand->execute();
$records = $result->getRecords();
$found = $result->getFoundSetCount();
 
 
if($found != 1){
 
$myhtml = "No Records Found!. Select near the middle of a parcel to get information about that parcel.";
$objResponse = new xajaxResponse();
$objResponse->script("myhtml = '$myhtml';");
return $objResponse;
}
else{
 
$row = 0;
foreach ($records as $record) {
  $taxid = $record->getField('TAXID_11');
  $lat = $record->getField('LATNUM');
  $lon =  $record->getField('LONNUM');
  $sub = $record->getField('SUBDIVISIO');
  $blk = $record->getField('BLOCK');
  $lot = $record->getField('LOT');
  $fname = $record->getField('FIRST_NAME');
  $grid = $record->getField('GRID_MOA');
  $totval = $record->getField('CURR_TOTAL_VALUE');
 
  $lname = $record->getField('LAST_NAME');
  $row++;
}
$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\\r\\n Legal: " . $sub . " " . $blk . " " . $lot . " \\r\\nOwner: ".$fname . " " . $lname . "\\r\\nFound: " . $found . "\\r\\nMoa Grid: " . $grid. "\\r\\nAssessed Value: " . $totval;
$myhtml2 = " Count: ". $row . " Taxid: ". $taxid . "<br />Legal: " . $sub . " " . $blk . " " . $lot . "<br />Owner: ".$fname . " " . $lname . "<br />Found: " . $found. "<br />Moa Grid: " . $grid. "<br />Assessed Value: " . $totval;
 
$objResponse = new xajaxResponse();
$objResponse->script("blk = '$blk';sub = '$sub';fname = '$fname';lname = '$lname';taxid = '$taxid';lot = 'lot';myhtml = '$myhtml';;myhtml2 = '$myhtml2'; grid = '$grid';totval = '$totval'");
 
return $objResponse;
 
}
}
?>

Open in new window

0
 
Roger BaklundCommented:
The code in the snippet only produces the output, it does not control where/when it is showed. There must be some other code where you connect the $myhtml string with the marker.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ALASKASTREETMASTERAuthor Commented:
the marker picks up the myhtml variable if a record is found. Why would it not pick up the same myhtml variable if no records were found?  Souldn't it be sending back the first part of the if statement when it did not find 1 record?
0
 
Roger BaklundCommented:
I think the if-else is working correctly, but the error is some where else. I have not seen the code that picks up the marker. Maybe it is dependant on one or more of the variables blk, sub, fname, lname, taxid or lot?
0
 
ALASKASTREETMASTERAuthor Commented:
Website.
http://www.streetmaster-ak.com/products/webimages/googlemaps.php
First  select search for the default location then click on the get parcel info link and then click on the middle of a parcel.  If you click in a road first it will come up blank even though I set the myhtml variable to 'Bob' fefore the  xajax_getll(lonquery,latquery) is run. So it must be getting something ie nothing from the function. If you next click on the middle of a parcel to get new info then back on a road the value in popup will be the same until you click on another parcel.

Below is the code for the google marker.
Thanks
function getlatnlon(){
 
getlnl = GEvent.addListener(map,"click", function(overlay, latlng) {
myhtml = "Bob";
  if (latlng) {
    latitude = parseFloat(latlng.y);
     longitude = parseFloat(latlng.x);
     latquery = (latitude  - 0.0001) +".."+(latitude  + 0.0001);
     lonquery = (longitude - 0.0001) +".."+(longitude  + 0.0001);
 
   xajax_getll(lonquery,latquery);
      map.openInfoWindow(latlng,myhtml2);
      }
});

Open in new window

0
 
ALASKASTREETMASTERAuthor Commented:
I spent some time clicking on the parcels and found that on small parcels the distance in my query from the click may pick up two parcels. Since this is not one record being found it is also failing and keeping the old value.  I plan to write some logic to ensure it will find the correct parcel. I wrote a routine in Acrobat that correctly Identified a parcel from incomming gps coordinates or closest parcl when  outside a parcel. It basically did the opposite, coordinates first then marker.  I plan to do that here too.

For this issue i checked again and cant see why it does not send back the No record found myhtml variable
.
appreciate your help!


0
 
Roger BaklundCommented:
xajax_getll(lonquery,latquery);
map.openInfoWindow(latlng,myhtml2);

I think this is the problem. Ajax is not like any function call. It is a two step process: first you send a request to the server, some time passes, then you fetch the response. xajax_getll() returns after the request is sent, it does not wait for the response. When the response returns, the javascript is executed, and myhtml2 becomes defined.
0
 
ALASKASTREETMASTERAuthor Commented:
It does bring back the correct value in each popup when the records found is 1.  I have the default mode for xajax set to : $xajax->configure( 'defaultMode', 'synchronous' ); so that it will wait for xajax to finish before going to the next line in the javascript. It appears to be working correctly as the info does show up in the google marker each time a parcel is clicked that the query finds just one record for. There is a slight pause, about a second, wehn clicking on a parcel before the popup displays the data.

Would it still not wait for the myhtml variable aslo when 0 or more than 1 records are found in the query?
Why would it send the myhtml value for querys where one record was found and not 0 or more than one. Dont make no sense.  Stumped.

appreciate your help.  will keep trying.
Thanks.
0
 
ALASKASTREETMASTERAuthor Commented:
should be myhtml2 in the previous post.
0
 
ALASKASTREETMASTERAuthor Commented:
thanks it was somewhere else.  Filemaker needed an error capture on the find request.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now