Solved

php xajax if else statement

Posted on 2009-04-09
11
353 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
  • 7
  • 4
11 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
Comment Utility
It seems you have a backslash too much here:

" \\r\\\nOwner: "

...it should be just:

" \\r\\nOwner: "
0
 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
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
Comment Utility
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
 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:ALASKASTREETMASTER
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
should be myhtml2 in the previous post.
0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now