I am having some error when i try to pass a variable via javascript
call to a php function.

I am trying to pass a state name to php so that it can search for all
records and pull it back with that name.


I keep getting an error saying:


Error displaying info: Alabama which tells me the value is being
passed but it is not being executing well as the query. Can anyone
assist with the code below and tell me what the problem is.


<script type="text/javascript">


function showlistingsbystate(thestate)
{
var thestate="Alabama";
document.getElementById('resultsTable').innerHTML = '<?php
displayCarListingsbyState("'+thestate+'");?>';



}


</script>

<?
/**
 * displayCarListings - Displays the car database table in
 * a nicely formatted html table.
 */
function displayCarListingsbyState($thestate){
   global $database;


   echo $thestate;


   $q = "SELECT
carid,zipcode,cartype,year,carmodel,state,mileage,timestamp "
       ."FROM ".TBL_SUBMITTED_CARS." WHERE state = '$thestate'";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
   $num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info" .$thestate;
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   echo '<img src="img/table_top.gif"  width="901" height="11" /


><table width="901" cellspacing="0" cellpadding="0">';


   echo '<tr class="headerRow"><th width=200>Make</th><th align=right
width=25><a rel="nofollow" href="#">Model</a></th><th align=right
width=20><a rel="nofollow" href="#">Year</a></th><th align=right
width=25><a rel="nofollow" href="#">Mileage</a></th><th align=right
width=25>Zipcode</th><th align=right width=25>State</th><th
align=right width=25><a rel="nofollow" href="#"><img src="img/
arr_desc.gif" border="0" width="16" height="16">&nbsp;Posted</a></
th></
tr>';
   for($i=0; $i<$num_rows; $i++){
      $carid  = mysql_result($result,$i,"carid");
      $cartype = mysql_result($result,$i,"cartype");
      $carmodel = mysql_result($result,$i,"carmodel");
      $year = mysql_result($result,$i,"year");
      $state = mysql_result($result,$i,"state");
      $zipcode = mysql_result($result,$i,"zipcode");
      $mileage  = mysql_result($result,$i,"mileage");
      $time   = mysql_result($result,$i,"timestamp");

   if ( $i&1 ){
    echo '<tr onclick="alert(\'Loading Car Page\')" title="'.
$cartype.'" class="evenRow" onmouseout="this.className=\'evenRow\';"
onmouseover="this.className=\'rollOverRow\';"><td>'.$cartype.'</
td><td>'.$carmodel.'</td><td>'.$year.'</td><td>'.$mileage.'</
td><td>'.
$zipcode.'</td><td>'.$state.'</td><td>'.date('Y-m-d', $time).'</td></
tr>';
   }
   else{
      echo '<tr onclick="alert(\'Loading Car Page\')" title="'.
$cartype.'" class="oddRow" onmouseout="this.className=\'oddRow\';"
onmouseover="this.className=\'rollOverRow\';"><td>'.$cartype.'</
td><td>'.$carmodel.'</td><td>'.$year.'</td><td>'.$mileage.'</
td><td>'.
$zipcode.'</td><td>'.$state.'</td><td>'.date('Y-m-d', $time).'</td></
tr>';
   }
 }
   echo '</table><img src="img/table_bottom.gif"  width="901"
height="11" /><br>';



}


?>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to