Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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计数错误_Php_Ajax_Count - Fatal编程技术网

php计数错误

php计数错误,php,ajax,count,Php,Ajax,Count,如您所见,我创建了下拉列表,并将其命名为字段名,还有count函数 我想做的是,如果一些人选择下拉菜单..显示有多少结果在数字中找到,如10,20,。。如果选择了第二个下拉列表,它将检查所选的两个下拉列表并通过结果计数..像这样连续..如果您想查看示例,我想要的是转到这里并选择汽车,计数将更新 我有ajax并且工作得很好,但是我无法在实时计算准确的PHP代码 AJAX代码 var xmlHttp function showCount(str) { xmlHttp=GetXmlHttpObje

如您所见,我创建了下拉列表,并将其命名为字段名,还有count函数

我想做的是,如果一些人选择下拉菜单..显示有多少结果在数字中找到,如10,20,。。如果选择了第二个下拉列表,它将检查所选的两个下拉列表并通过结果计数..像这样连续..如果您想查看示例,我想要的是转到这里并选择汽车,计数将更新

我有ajax并且工作得很好,但是我无法在实时计算准确的PHP代码

AJAX代码

var xmlHttp

function showCount(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="phpApplication.php";
url=url+"?action=count2";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("countR").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
PHP代码

function dropdown($field, $table)
{ 
  //initialize variables
  $oHTML  = '';
  $result = '';

  //check to see if the field is passed correctly
  if (($field == "")||($table == ""))
  {
    die("No column or table specified to create drop down from!");
  }

  $sql = "select distinct($field) from $table";

  //call the db function and run the query
  $result = $this->conn($sql);

  //if no results are found to create a drop down return a textbox
  if ((!$result) ||(mysql_num_rows($result)==0))
  {
    $oHTML .= "<input type='text' name='$field' value='' size='15'>";
  }elseif (($result)&&(mysql_num_rows($result)>0)){


    //build the select box out of the results
    $oHTML .= "<select name='$field' onchange='showCount(this.value)'>\n<option value='all'>All</option>\n";
    while ($rows = mysql_fetch_array($result))
    {
      $oHTML .= "<option value='".$rows[$field]."' name='".$rows[$field]."'>".$rows[$field]."</option>\n";

    }
    $oHTML .= "</select>\n";

  }
  //send the value back to the calling code
  return $oHTML;
}//end function

function count1(){

      $sql2 = "SELECT SQL_CALC_FOUND_ROWS * from produkt_finder_table where Bauform_d ='".($_POST['Bauform_d'])."' ";
      $query = $this->conn($sql2);
      $result = mysql_query( $query );
      $count  = mysql_result( mysql_query( 'SELECT FOUND_ROWS()' ), 0, 0 );
      echo $count;
      //$sql2 = "SELECT COUNT(Bauform_d) from produkt_finder_table where Bauform_d = 'mobil' "; 

     //echo var_dump($result1);
     while($row = mysql_fetch_array($query))
     {
    // echo  $row['COUNT(Bauform_d)'];
     }
      //echo mysql_num_rows($query);
    //  if (isset($_POST['Bauform_d']))
//{
    /* if (mysql_num_rows($result)==0) {
         echo '0';
         } else {
     echo mysql_num_rows($result);
     $row = mysql_fetch_array($result);

     echo $result;
     echo $row['COUNT(Bauform_d)'];
    //   }
}*/
}

$action = $_GET['action'];

$proFin = new Application();

switch($action) {

        case 'show':
            $proFin->show_form();
        break;

        case 'search':
            $proFin->search();
        break; 

        case 'searchAll':
            $proFin->searchAll();
        break; 


        case 'count2':

            $proFin->count1();

        break; 

        }

你调试了哪些部分

将count1函数更改为仅回显时间或使用时间的内容

然后,如果它返回正确的值,您就知道您的JS正在工作,并且您的PHP脚本正在调用正确的函数

我假设PHP代码不起作用,因为SQL查询正在查找$\u POST['Bauform\u d'],这在调用xmlHTTP请求时没有设置。运行一个简单的print\u r$\u POST;确保正在传递查询中所需的所有数据。如果没有,则更改JS代码以传递值-当您确定php脚本传递了所有正确的变量时,然后开始添加回SQL查询中,等等。

调试


雅各布的答案才是关键。

请格式化您的代码。是否在实时计算?另外,您知道mysql有一个计数函数吗?代码看起来,从快速浏览,很好。您如何确定记录计数是错误的?如果不访问数据,我们无法判断。我想,我检查了计数,它现在工作正常,我的意思是它计数正确…现在我的问题是,它无法通过我传递的ajax函数显示准确的计数结果。。