gpt4 book ai didi

php - 如何使用codeigniter循环从mysql检索数据

转载 作者:行者123 更新时间:2023-11-29 22:28:55 25 4
gpt4 key购买 nike

我有一个问题,我将在我的sql中检索多个数据,例如我有9个数据,但我的问题是在我的foreach内部将要处理的数据并且foreach被放置在我的 Controller 中。

这是我的 Controller :

function getPhaseData() {
try
{
$this->SessionCheck();
$this->user->initialize($this->session->userdata('userid'));

$this->load->model('project_model', 'Project');
$ProjectID = $this->input->post('ProjectID');

/***************** Intialize Project model ******************/
$this->Project->Initialize($ProjectID);
$Options = Work_breakdown_structure::$WithBaseTaskID;
//$PhaseTaskID = (int)$this->input->get_post('TaskID',TRUE);


//$PhaseTaskID = $this->Project->getPhaseBaseTaskID($ProjectID);

$postlist->phaseList = $this->Project->LatestApplicablePlan->WBS->GetPhaseList($Options);
$PhaseList = $this->Project->LatestApplicablePlan->WBS->GetPhaseList($Options);

foreach($PhaseList as $row)
{
$postlist->taskList = $this->Project->LatestApplicablePlan->WBS->GetWBS($Iterate['TaskID'], $Options);
}


/*if($PhaseTaskID == null)
{ }
else
{
foreach($PhaseTaskID as $index=>$value)
{
$finalArr[$value['baseTaskID']] = $value['baseTaskID'];

//echo $finalArr[$value['baseTaskID']].' ';
$postlist->taskList = $this->Project->LatestApplicablePlan->WBS->GetWBS($finalArr[$value['baseTaskID']], $Options);
}
}*/


$postlist->project = $ProjectID;
return $this->load->view('MyToDoPhaseDropdown', $postlist);
}

这是我的 View ,我将在选择下拉列表中显示从 Controller 获取的数据。

if($project == 0) {
echo '<td style="padding-top:5x;font-size:14px;" colspan="2"> <br> Phases : ';

echo '<select disabled id="phases_select" style="width:400px;" onchange="search_filter()" >';

echo '<option value="0" selected="selected"> Select Project Phase </option>';

echo '</select>';
echo '</td>';
}
else
{
foreach($taskList as $iterate)
{
echo ' TaskID: '. ' '.$iterate['TaskID'] .' -- TaskName: '. $iterate['TaskName'].'<br>' ;
}

/*foreach($phaseList as $row) {
echo 'TaskID: '. $row['TaskID'].' '.$row['TaskName'].'<br>';
if(preg_match("/^CYCLE/", strtoupper($row['TaskName'])))
{
foreach($row['Child'] as $child) {
echo 'TaskID: '. $child['TaskID'].' '.$child['TaskName'].'<br>';
}
}
}*/

echo '<td style="padding-top:5x;font-size:14px;" colspan="2"> <br> Phases : ';
echo '<select id="phases_select" style="width:400px;" onchange="search_filter()" >';
echo '<option value="0" selected="selected"> Select Project Phase </option>';
foreach($phaseList as $row)
{
if(preg_match("/^CYCLE/", strtoupper($row['TaskName'])))
{
foreach($row['Child'] as $child)
{
if($Iterate['BaseTaskID'] != $child['TaskID'])
{
echo '<option value="'. $child['TaskID']. '">';
echo $row['TaskName'].' > '.$child['TaskName']. '</option>';
}

foreach($taskList as $Iterate)
{
if($child['TaskID'] == $Iterate['BaseTaskID'])
{
echo '<option value="'. $Iterate['TaskID']. '">';
echo $row['TaskName'].' > '.$child['TaskName'].' '.$Iterate['IterationNumber']. '</option>';
}
}
}
}

else
{
if($Iterate['BaseTaskID'] != $row['TaskID'])
{
echo '<option value="'. $row['TaskID']. '">';
echo $row['TaskName'].'</option>';
}

foreach($taskList as $Iterate)
{
if($row['TaskID'] == $Iterate['BaseTaskID'] )
{
echo '<option value="'. $Iterate['TaskID']. '">';
echo $row['TaskName'].' '.$Iterate['IterationNumber']. '</option>';
}
}
}
}
echo '</select>';
echo '</td>';
}

最佳答案

这不是确切的答案,但这将有助于理解 codeigniter 中的 MVC 结构。

型号

  function get_city_list(){
$this->db->select('city_id, name');
$this->db->where('status', 1);
$this->db->order_by("name", "asc");
$this->db->from('city');
$query = $this->db->get();
$result = $query->result();
return $result;
}

Controller

    function listing(){
$data['city'] = $this->home->get_city_list();
$this->load->view('property_listing', $data);
}

查看

    foreach($city as $cty){
echo $cty->name;
echo $cty->city_id;
}

希望这对你有帮助..

关于php - 如何使用codeigniter循环从mysql检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com