2017-03-09 85 views
0

我的工作(在冷杉時間)MVC模式和顯示錯誤警告,當我遇到一些問題時顯示錯誤...不知道如何使用的foreach

例如我這

控制器:

include_once(UserModel.php); 

$userdata = new User_Model(); 
$biography = $userdata->Get_UserBio(); 

型號:

include_once(conexion.php); 

       //I make my prepared query and... 
       if ($user_infoprofile->execute()): 

        $data= $user_infoprofile->get_result(); 

        if ($data->num_rows): 
         while ($result=$data->fetch_array()): 
         $this->userbio[]=$result; 
         endwhile; 
        else: 
         //I want to display something like 
         $error= "you have to fill your bio", 
         echo $error; 
        endif; 
       else: 
        $error="invalid request"; 
        echo $error; 
       endif; 
       return $this->userbio; 
       $user_infoprofile->close(); 

查看:

include_once(UserController.php); 

//if there are rows in the array I display 

foreach... 

//But heres my problem... if there are not rows in the array... I want to display something else 

我該怎麼辦?我在這方面是初學者,還是有其他更乾淨的方法來做到這一點?

+0

一個小錯誤 $ error =「你必須填寫你的生物」,在這裏你以逗號結尾,只是以分號結尾並嘗試 – Umar

回答

0

require函數中使用引號。像這樣:include_once('UserModel.php');。如果你想顯示所有的錯誤,你可以用這個行做到這一點:

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 
0
if(empty($var_array)){ 
echo "There is not results..."; 
     }else{ 
foreach.... 
     } 

你的意思是如何檢查,如果數組是空的?

+0

使用它會拋出'undefined index'錯誤 – kukiko11

+0

檢查什麼值獲取$ data,因爲if ü選擇不檢索anythim,$數據將是空的 – JuJoGuAl

+0

我的意思是如何填充數組與警告消息,以防查詢找不到任何行,以這種方式我可以使用foreach向用戶顯示消息 – kukiko11

-1

好的,但問題是如何doit在我的view.php文件的特定部分...因爲如果我使用'回聲'此消息將出現在任何地方,而不是我想要的地方...