Loop不会返回给定记录的所有值

I am new to PHP and coding:

For each record, the function below only returns the "code" variable values in $myChallenge. However, I need the other variable values (e.g. partnerName, challengeTitle, image_url) for each record in order to use them in subsequent functions that use $myChallenge.


Controller

public function getChallenge(){
    //challengenames
    $link=$this->dbPrototype();
    $query="select * from challengestable where status=0 ORDER BY date DESC";
    $result=$link->query($query);
    while($row=mysqli_fetch_array($result)) {
        $myChallenge[$row['challengeId']] = $row;
    }
    return $myChallenge;
}




public function viewChallengesAction(){
        //get instance for request
    $request = JO_Request::getInstance();
        //get activated challengenames
    $myChallenge=$this->getChallenge();
    $this->view->challengenames = array();
    foreach($myChallenge AS $k=>$challengename){
        $this->view->challengenames[$k]['href'] = WM_Router::create($request->getBaseUrl() . '?module=challenges&controller=index&action=yourChallenge?code=' . $k);
        $this->view->challengenames[$k]['title'] = $challengename['title'];
    }

View

<?php if ($this->challengenames && is_null($this->tag)) { ?>
    <div id="browsecats">
        <div class="list">
            <ul>
                <?php foreach($this->challengenames as $k=>$challengename) { ?>
                    <li><a href="<?php echo $challengename['href']; ?>"><?php echo $challengename['title']; ?></a></li>
                <?php } ?>
            </ul>
            <div class="clear"></div>
        </div>
    </div>
<?php }?>

=============

ViewChallenge

<?php echo $this->header_part; ?>

<div id="defaultcontainerwrapper" class="maxwidth">
    <?php foreach($this->challengenames as $k=>$challengename) { ?>
        <header>
            <h1>
                <div class="list">
                    <span>Welcome to </span><?php echo $challengename['partnerName']; ?><span>'s Beat Waste Challenge!</span>
                </div>
            </h1>
        </header>
    <?php } ?>
</div>

<?php echo $this->footer_part; ?>

Put the entire row into $myChallenge:

while ($row = mysqli_fetch_array($result)) {
    $myChallenge[$row['code']] = $row;
}

Now $myChallenge will be a 2-dimensional array. You can access values like

$myChallenge[$code]['partnerName'];