-1

我无法从 PHP 中的 MySQL 查询中获取行数。

测试页面的链接和PHP代码如下:

<?php 

$con=* TESTED AND WORKING *

// Check connection

if (mysqli_connect_errno($con))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


$retDiv = "";

$counter = 0;

$result = mysqli_query($con,"SELECT * FROM  `store` ORDER BY  `num` DESC ");
$num_rows = mysql_num_rows($result);

while($row = mysqli_fetch_array($result))
{
    if ($counter>=5)
    {   
        break;
    }
    else
    {   
        $retDiv = "<div id=\"hs" . $row['num'] . "\" class=\"store-item " . $row['Artist'] . "\">\n";
        $retDiv = $retDiv . "<div id=\"". $row['Release'] . "-title\" class=\"album-title\">\n";
        $retDiv = $retDiv . "<h1 align=\"center\" style=\"text-transform:uppercase;\">" . $row['Release'] . "</h1></br>\n";
        $retDiv = $retDiv . "<h3 align=\"center\">" . $row['ReleaseName'] . "</h3>\n";
        $retDiv = $retDiv . "</div>\n";
        $retDiv = $retDiv . "<div id=\"" . $row['Release'] . "-description\" class=\"description\">\n";
        $retDiv = $retDiv . "<table width=\"100%\">\n";
        $retDiv = $retDiv . "<td width=\"50%\" style=\"padding-left:57px;padding-right:57px;padding-top:57px;padding-bottom:20px;\">\n";
        $retDiv = $retDiv . "<a id=\"" . $row['Release'] . "DivLink\" href=\"javascript:;\" onmousedown=\"toggleDivStore('" . $row['Release'] . "-expand','" . $row['Release'] . "DivLink','" . $row['Release'] . "','" . $row['Release'] . "b','" . $row['Release'] . "')\"><img name=\"" . $row['Release'] . "-art\" src = \"images/" . $row['Release'] . ".jpg\" class=\"album-art\" onmouseover=\"this.src='images/" . $row['Release'] . "b.jpg'\" onmouseout=\"this.src='images/" . $row['Release'] . ".jpg'\"></a>\n";
        $retDiv = $retDiv . "<td width=\"50%\" style=\"padding:20px;padding-top:0px;padding-bottom:0px;padding-left:0px;\">\n";
        $retDiv = $retDiv . "<p style=\"\">" . $row['Description'] . "</p>\n";
        $retDiv = $retDiv . "</td>\n";
        $retDiv = $retDiv . "</table>\n";
        $retDiv = $retDiv . "</div>\n";
        $retDiv = $retDiv . "<div class=\"album-expand\" id=\"RELEASE-expand\" style=\"display:none;\">\n";
        $retDiv = $retDiv . "</div>\n";
        $retDiv = $retDiv . "<div =\"" . $row['Release'] . "PaypalContainer\" class=\"album-paypal-container\">\n";
        $retDiv = $retDiv . $row['Paypal1'];
        $retDiv = $retDiv . "</div>\n";
        $retDiv = $retDiv . "</div>\n";

        echo $retDiv;
    }
    $counter = $counter+1;
}


echo "<div id=\"retNum\"><script type=\"text/javascript\">numReleases =" . $num_rows . ";numPages=Math.ceil(numReleases/5)-1;</SCRIPT></div>";

mysqli_close($con);

如何返回 Javascript 的行$num_rowsretNum

4

3 回答 3

0

您正在混合 mysqli(注意i)和 mysql(注意 i 的LACK)。这两个库和函数体不可互操作:

$num_rows = mysql_num_rows($result);
                 ^--- missing an `i` here
于 2013-07-12T16:25:34.887 回答
0

When you are using mysqli_query() method to get the result set from the database, the number of rows from the result can be obtained by calling mysqli_num_rows() method which takes the mysqli_result set as the argument and do not use mysql_num_rows(). Check mysqli_num_rows()

于 2013-07-12T16:39:55.183 回答
0

与其使用 PHP 逻辑突围,不如在你的 sql 查询中添加“LIMIT 5”?

于 2013-07-12T16:51:33.857 回答