mysql没有正确过滤select语句

nzkunb0c  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(247)

这个问题在这里已经有答案了

我可以在php中混合mysql api吗(4个答案)
两年前关门了。
$result->num\u rows返回值64(所有记录),此时它应该返回值29,$counter返回值0,表示没有记录。我认为这是我事先准备好的声明中的一个问题,但我不完全确定它可能是什么。
ajax

$.ajax
({
  url: 'query.php',
  type: 'POST',
  data: {Category: cat},
  //dataType: 'json',  
  success: function(result) 
  {  
    if(result) 
    {   
      console.log(result);          
    }
  },
  error: function() 
  {
    alert("error");
  }      
}); // end ajax call

PHP

<?php
require '_conn/connection.php'; 

$stmt = $conn->prepare("SELECT * FROM portfoliotb WHERE Category = ?");
$stmt->bind_param('s', $cat); 
$cat = $_POST['Category'];
$stmt->execute();

$result = $stmt->get_result();

if ($result->num_rows > 0) 
{
    echo $result->num_rows.",";
} 
else 
{
    echo "0 results";
}

$records = [];
$counter=0;

while( $row = mysql_fetch_row( $result ) )
{
    $counter++;

    //$records[] = array('Id' => $row['Id'], 'Category' => $row['Category'],'Directory' => $row['Directory'],'Description' => $row['Description'],'Code' => $row['Code']);
    //array_push( $records, $row['Category'] );   
    //array_push( $records, array("Id"=>$row['id'],"Category"=>$row['Category'],"Directory"=>$row['Directory'],"Description"=>$row['Description'],"Code"=>$row['Code'])); 
}

echo $counter;
//echo json_encode( $records );

?>

b4wnujal

b4wnujal1#

通过拆除管线解决了问题

while( $row = mysql_fetch_row( $result ) )

把它换成线

while( $row = $result->fetch_assoc() )

谢谢你的帮助

相关问题