为什么这个mysqli查询没有获取?

时间:2016-01-24 15:02:11

标签: php mysqli

为什么这个表没有取出?在这一个查询中,我一直在睁大眼睛超过一个小时。我疯了。

我已经在phpmyadmin中测试了这个查询,它正在运行......

$query = "
SELECT e.earning_link_id, COUNT(e.earning_id) AS visits, ABS(TIMESTAMPDIFF(DAY, now(), l.link_created)) AS age, l.link_link, o.owner_id
FROM earnings AS e
INNER JOIN links AS l
ON e.earning_link_id = l.link_id
LEFT JOIN owners as o
ON l.link_id = o.owner_link_id
WHERE o.owner_id > 0
GROUP BY earning_link_id
ORDER BY COUNT(e.earning_id) / ABS(TIMESTAMPDIFF(DAY, now(), l.link_created)) DESC
LIMIT 10
";
if ($statement = $mysqli->prepare($query))
{
        $statement->execute();
        $statement->store_result();
        $statement->bind_result($link_id, $link_visit_count, $link_age, $link_link, $link_owner_id);

        echo '<table>';
        while ($statement->fetch())
        {
            echo '<tr>';
                echo '<td><i class="fa fa-link"></i> '.$link_link.'</td>';
            echo '</tr>';
        }
        echo '</table>';

    $statement->free_result();
    $statement->close();
}

1 个答案:

答案 0 :(得分:1)

尝试删除 - &gt; store_result();

<?php   
   $mysqli = new mysqli("localhost", "root", "", "test");
    $query = " SELECT 1 as id, 2 AS visits, 3 AS age, 4 as link_link,5 as owner_id  ";
    if ($statement = $mysqli->prepare($query))
    {
            $statement->execute();
            $statement->bind_result($link_id, $link_visit_count, $link_age, $link_link, $link_owner_id);

            echo '<table>';
            while ($statement->fetch())
            {
                echo '<tr>';
                    echo '<td><i class="fa fa-link"></i> '.$link_id.'</td>';
                    echo '<td><i class="fa fa-link"></i> '.$link_visit_count.'</td>';
                    echo '<td><i class="fa fa-link"></i> '.$link_age.'</td>';
                    echo '<td><i class="fa fa-link"></i> '.$link_link.'</td>';
                    echo '<td><i class="fa fa-link"></i> '.$link_owner_id.'</td>';
                echo '</tr>';
            }
            echo '</table>';

        $statement->close();
    }

    $mysqli->close();

?>

这项工作,测试并更改您的查询