php - Mysql is not fetching all the data -


<?php     include('config.php');      $isd=mysql_real_escape_string( $_get['q'] );     $sql=mysql_query("select zip zipcod abb='$isd' ") or ;       while( $row=mysql_fetch_array( $sql, mysql_assoc ) ){         $zip=$row['zip'];         echo '<option>'.$zip.'</option> ';     } ?> 

this ajax

<script>     function showuser(str) {         if (str=="") {             document.getelementbyid("zzips").innerhtml="";             return;         }         if (window.xmlhttprequest) {         // code ie7+, firefox, chrome, opera, safari             xmlhttp=new xmlhttprequest();         } else { // code ie6, ie5             xmlhttp=new activexobject("microsoft.xmlhttp");         }          xmlhttp.onreadystatechange=function() {             if (xmlhttp.readystate==4 && xmlhttp.status==200) {                 document.getelementbyid("zzips").innerhtml=xmlhttp.responsetext;             }         }         xmlhttp.open("get","getstate.php?q="+str,true);         xmlhttp.send();     } </script> 

html

<select name="states"onchange="showuser(this.value)">  	<option value="al">al</option>  	<option value="ak">ak</option>  	<option value="az">az</option>  	<option>ar</option>  	<option>ca</option>  	<option>co</option>  	<option>ct</option>  	<option>de</option>  	<option>fl</option>  	<option>ga</option>  	<option>hi</option>  	<option>id</option>  	<option>il</option>  	<option>in</option>  	<option>ia</option>  	<option>ks</option>  	<option>ky</option>  	<option>la</option>  	<option>me</option>  	<option>md</option>  	<option>ma</option>  	<option>mi</option>  	<option>mn</option>  	<option>ms</option>  	<option>ms</option>  	<option>mt</option>  	<option>ne</option>  	<option>nv</option>  	<option>nh</option>  	<option>nj</option>  	<option>nm</option>  	<option>ny</option>  	<option>nc</option>  	<option>nd</option>  	<option>oh</option>  	<option>ok</option>  	<option>or</option>  	<option>pa</option>  	<option>ri</option>  	<option>sc</option>  	<option>sd</option>  	<option>tn</option>  	<option>tx</option>  	<option>ut</option>  	<option>vt</option>  	<option>va</option>  	<option>wa</option>  	<option>wv</option>  	<option>wi</option>  	<option>wy</option>  </select>     

this code fetching zip codes of states co, nj, not all. can let me know error display zip codes according states selected in first drop down

thanks help.

there minor error in php - omit condition after or statement.

<?php     include('config.php');      $isd=trim( mysql_real_escape_string( $_get['q'] ) ); /* or? */     /* table called `zipcod` or `zipcode`? */     $sql=mysql_query( "select `zip` `zipcod` trim( `abb` )='$isd';" ) or die('bad mojo');       while( $row=mysql_fetch_array( $sql, mysql_assoc ) ){         $zip=$row['zip'];         echo '<option>'.$zip.'</option> ';     }     mysql_free_result( $sql );  ?> 

to aid debugging javascript / ajax request:

function showuser(str) {     var dbg=true;     if( dbg )console.group('showuser');      if( str=="" ) {         document.getelementbyid("zzips").innerhtml="";         if( dbg )console.warn('empty string');         return;     }     if( dbg )console.info( 'initial value passed ajax function: %s ',str );       xmlhttp=window.xmlhttprequest ? new xmlhttprequest() : new activexobject("microsoft.xmlhttp");     if( dbg )console.info( 'xhr object created: %s', xmlhttp );      xmlhttp.onreadystatechange=function() {         if( xmlhttp.readystate==4 && xmlhttp.status==200 ) {             document.getelementbyid("zzips").innerhtml=xmlhttp.responsetext;             if( dbg )console.info('response received: %s', xmlhttp.responsetext )         }     }     xmlhttp.open( "get", "getstate.php?q="+str, true );     if( dbg )console.info('connection opened');      xmlhttp.send();     if( dbg )console.info('request sent'); }    

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -