php - 查询没有得到所有的价值

时间:2014-01-22 03:24:31

标签: php mysql

请检查我的以下代码我有6条记录也显示在$ count打印但在数组中只获得5条记录..请检查我在哪里做错了

session_start();
$friendlyurl=$_SESSION['favcolor']; 


include('adminv/dsn.php');
$data = mysql_query("SELECT autoid FROM propertydetails where  friendlyurl='$friendlyurl'")
or die(mysql_error());
$info = mysql_fetch_array( $data ); 
$autoid=$info['autoid'];
echo "auto id ".$autoid."<br>";

include 'config.php';
$rows = array();
$conn = @new mysqli($server,$user,$pass,$db) or die('unable to connect');
$query = "select count(*) from images where parentid=$autoid and description<>'Not Active'";
$result = $conn->query($query);
list($count) = $result->fetch_row();
$query = "select path, description from images where parentid=$autoid and  description<>'Not Active'";
$result = $conn->query($query);
$checkimageexist = $count;
echo "check count ".$checkimageexist; // count shows there are 6 records
while($row = $result->fetch_array())
    $rows[] = $row;
    print_r(array_values($rows)); // getting 5 record instead of 6

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我认为你有5条记录。 试试这段代码:

$conn = @new mysqli($server,$user,$pass,$db) or die('unable to connect');
$query = "select count(*) as f_val from images where parentid=$autoid and description<>'Not Active'";
$result = $conn->query($query);
$count = ($result->fetch_row())["f_val"];