0

true または false だけを返す if else ステートメントはほとんどなく、すべてのステートメントが正しく機能していません。私は多くの方法を試しましたが、問題がわかりません.誰かがこれを修正すると非常に役に立ちます.

ここにモデルの私のコードがあります

function exists($email){
    $this->db->where('email',$email);
    $query=$this->db->get('member_info');
    echo "model is called"; // after execution this text is shown but not the others
    if ($query->num_rows == 1) {           
        return true;        
        echo "i got one";
    }else{
        return false;
        echo "i got nothing";
    }       
}

ここに私のコントローラーがあります

function is_exists($email){
    echo "this is loaded";  //this line works properly
    if($this->validation_model->exists($email)){
        return false;
        echo "true"; //this doesn't 
    }else{
        return true;
        echo "false"; // this doesn't
    }
}
4

7 に答える 7

3

エコー部分を印刷する前に関数を返しています。戻る前にエコーする必要があります。

また、行を変更して複数をチェックします

if ($query->num_rows() > 0 ) {

アップデート

この方法を試してください。それに応じてテーブル名、id 値を置き換えます。

$query = $this->db->query("select id form your_table where email=".$email);
if ($query->num_rows() > 0 ){
echo "i got one";
return true;
}
else{
echo "i got nothing";
return false;
}

また、電子メールが存在する場合に false を返すコントローラー ロジックを確認してください。コントローラの true false を返すように変更した方がよいでしょう。

于 2013-07-11T06:13:12.163 に答える
1

のようにしてみてください

if($this->validation_model->exists($email)){
    echo "true";
    return false; 
}else{
    echo "false";
    return true;
}  

エコーを前に置くreturnと、次のようになります

$query->num_rows()
于 2013-07-11T06:10:44.677 に答える
1

を使用しているためreturn、以降のコードreturnは実行されません

return false;
echo "true"; // this doesn't because you have return before this line

return true;
echo "false"; // this doesn't because you have return before this line
于 2013-07-11T06:10:48.707 に答える
0

モデルは次のようにする必要があります。

if ($query->num_rows == 1) {           
    return true;        
}else{
    return false;
}

追加のエコーを出力する必要はありません。コントローラーと同じ話

if($this->validation_model->exists($email)){
    return false;
}else{
    return true;
}

私が知る限り、return ステートメントの後で (関数が戻るときに) コードを実行することはできません。

私の解決策は次のとおりです。

あなたのコントローラーにこのように入れます

if($this->validation_model->exists($email)){
    echo "EMAIL EXIST";
}else{
    echo "EMAIL DOES NOT EXIST";
}
于 2013-07-11T06:15:06.547 に答える
0
//num_rows() is a function
<?php 

function exists($email){
    $this->db->where('email',$email);
    $query=$this->db->get('member_info');
    echo "model is called"; // after execution this text is shown but not the others

    //num_rows() is a function
    if ($query->num_rows() == 1) {

        //add message before return statement
        echo "i got one";
        return true;


    }else{

        echo "i got nothing";
        return false;

    }
}
于 2013-07-11T06:12:18.730 に答える
0

これを変える:

if ($query->num_rows == 1) { 

これに:

if ($query->num_rows() == 1) { 

そして、以下を変更します。

if ($query->num_rows() > 0 ){
    echo "i got one";
    return true;
}
else{
    echo "i got nothing";
    return false;
}
于 2013-07-11T06:10:29.370 に答える
0

この行を変更します。

if ($query->num_rows() == 1) {    
于 2013-07-11T06:11:02.420 に答える