2017-03-09 83 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文件的特定部分...因为如果我使用'回声'此消息将出现在任何地方,而不是我想要的地方...