duansen6750 2015-05-08 13:53
浏览 42
已采纳

MySQL获取数组不收集并返回所有行| PHP | MySQL的

I have a function (see below)

public function ReadBets_Open($id) {
    $queryBase = "SELECT * FROM `vr_wp_bets` WHERE `is_open` = 'true' AND `id` = '%s';";
    $queryBase2 = sprintf($queryBase, $id);
    $selectQuery = mysql_query($queryBase2);
    $return = "<div style='max-height: 400px; overflow: scroll;'>";
    while ($result = mysql_fetch_array($selectQuery)) {
        //var_dump($result);
        $return = "<div style='border: 1pt solid black; width: 99%;'>";
        $return .= "<h2>" . $result['title'] . "</h2>";
        $return .= "<table>";

        $return .= "<tr><td style='width:50%;'>Sport: </td><td>" . $result['sport'] . "</td></tr>";
        $return .= "<tr><td style='width:50%'>Participant: </td><td>" . $result['participant'] . "</td></tr>";
        $return .= "<tr><td>Market: </td><td>" . $result['market'] . "</td></tr>";
        $return .= "<tr><td>Time: </td><td>" . date("H:i", strtotime($result['bettilltime'])) . "</td></tr>";
        $return .= "<tr><td>Odds: </td><td>" . $result['odds'] . "</td></tr>";
        $return .= "<tr><td>Stake: </td><td>&pound;" . $result['stake'] . "</td></tr>";

        if ($result['is_ew'] == "true") {
            $return .= "<tr><td>Each Way: </td><td>" . $this->CalculateEachWay($result['odds'], $result['ew_odds']) . "</td></tr>";
            $return .= "<tr><td>Estimated Return:</td><td>" . "N/A" ."</td></tr>";
        }
        else if ($result['odds'] == "SP") {
            $return .= "<tr><td>Estimated Return:</td><td>" . "N/A" ."</td></tr>";
        }
        else {
            $return .= "<tr><td>Estimated Return:</td><td>&pound;" . $result['estimated_return'] ."</td></tr>";
        }

        $return .= "</table>";
        $return .= "</div><br>";
    }
    $return .= "</div>";
    return $return;
}

And I know for a fact that there is 4 results in this that should be selected, however only one is returned by the fetch array, I was wondering if anyone can see an issue with this and if so what is it? This has had me stumped for a few days now and I really need an answer to this.

The way that I call the method is:

$classInstance->ReadBets_Open($current_user->ID);




NOTE
I am aware that I am using depreciated mysql_* functionality, this will be changed in the future, this needs to be made and released.

  • 写回答

1条回答 默认 最新

  • douba8758 2015-05-08 13:57
    关注

    You are resetting $return each time you loop. So by the end of the loop $return will only have the last row's details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来