Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql没有获取所有数据_Php_Ajax - Fatal编程技术网

Php Mysql没有获取所有数据

Php Mysql没有获取所有数据,php,ajax,Php,Ajax,$sql=mysql\u查询(“从zipcod中选择zip,其中abb='$isd'))或 您的代码中是否也遗漏了某些内容,或者在此处再次键入时遗漏了某些内容?也许你应该有一些类似于或死(“错误消息”) php中有一个小错误-您省略了或语句后面的条件 <script> function showUser(str) { if (str=="") { document.getElementById("zzips").innerHTML=""

$sql=mysql\u查询(“从zipcod中选择zip,其中abb='$isd'))或


您的代码中是否也遗漏了某些内容,或者在此处再次键入时遗漏了某些内容?也许你应该有一些类似于或死(“错误消息”)

php中有一个小错误-您省略了
语句后面的条件

<script>
    function showUser(str) {
        if (str=="") {
            document.getElementById("zzips").innerHTML="";
            return;
        }
        if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        } else { // code for 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>

如果您在mysql或Heidi之类的gui中手动运行查询,您会得到一些状态的预期结果吗?是的,我不会从其他状态获取值。它只在CO和NJI上工作,因此我建议,如果在gui中手动运行查询时无法获得预期的结果,那么问题在于数据库中的数据。你能确认db确实包含引起问题的州的相关数据吗?好的,太多了。。事实上,问题是以DB为单位的状态存储在一个空白处。现在我必须删除所有空白。我编辑了上面的内容,包括
trim
,这应该会有帮助!
<script>
    function showUser(str) {
        if (str=="") {
            document.getElementById("zzips").innerHTML="";
            return;
        }
        if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        } else { // code for 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>
<?php
    include('config.php');

    $isd=trim( mysql_real_escape_string( $_GET['q'] ) ); /* or? */
    /* Is the table actually called `zipcod` or `zipcode`? */
    $sql=mysql_query( "SELECT `zip` FROM `zipcod` where 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 );

?>
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 to 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');
}