php - While Loop Won't return all values of a given record -


i new php , coding:

for each record, function below returns "code" variable values in $mychallenge. however, need other variable values (e.g. partnername, challengetitle, image_url) each record in order use them in subsequent functions use $mychallenge.


controller

public function getchallenge(){     //challengenames     $link=$this->dbprototype();     $query="select * challengestable status=0 order date desc";     $result=$link->query($query);     while($row=mysqli_fetch_array($result)) {         $mychallenge[$row['challengeid']] = $row;     }     return $mychallenge; }     public function viewchallengesaction(){         //get instance request     $request = jo_request::getinstance();         //get activated challengenames     $mychallenge=$this->getchallenge();     $this->view->challengenames = array();     foreach($mychallenge $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 $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 $k=>$challengename) { ?>         <header>             <h1>                 <div class="list">                     <span>welcome </span><?php echo $challengename['partnername']; ?><span>'s beat waste challenge!</span>                 </div>             </h1>         </header>     <?php } ?> </div>  <?php echo $this->footer_part; ?> 

put entire row $mychallenge:

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

now $mychallenge 2-dimensional array. can access values like

$mychallenge[$code]['partnername']; 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -