Solved

php xajax if else statement

Posted on 2009-04-09
11
366 Views
Last Modified: 2013-12-13
$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
Comment
Question by:ALASKASTREETMASTER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24112921
It seems you have a backslash too much here:

" \\r\\\nOwner: "

...it should be just:

" \\r\\nOwner: "
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24113159
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24113186
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!

 

Author Comment

by:ALASKASTREETMASTER
ID: 24115373
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
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24115605
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24118481
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24118652
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
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24118886
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24120540
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
 

Author Comment

by:ALASKASTREETMASTER
ID: 24120543
should be myhtml2 in the previous post.
0
 

Author Comment

by:ALASKASTREETMASTER
ID: 24128944
thanks it was somewhere else.  Filemaker needed an error capture on the find request.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question