dsm42026 2012-12-19 15:59
浏览 24
已采纳

将返回的字符串传递给另一个字符串并在if语句中使用它[关闭]

I have this piece of code:

<?php
            require_once 'Membership.php';
    $membership = New Membership();
    $AccountType = $membership->is_Account($currUser);
    if ($AccountType == 'S') {
        echo '<li>';
        echo $AccountType;
        echo '</li>';
    }
   ?>

Which calls upon a different document membership.php with a function that does this:

function is_Account($currUser){
    //Find out if user is a buyer or a seller
    $mysql = New Mysql();
    $mysql->get_Account($currUser); 
}

Which for organisational reasons - goes to a document (this bit works, as other functions work successfully) that does this:

function get_Account($currUser) {
    $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$mysqli) {
        die('There was a problem connecting to the database.');
    }       
    $queryAcct = "SELECT Id
            FROM Users
            WHERE Username = '$currUser'
            LIMIT 1";
    if ($Result = $mysqli->query($queryAcct)){
        if (!$Result) {
            echo 'Could not run query: ' . mysql_error();
            exit;
        }
        else {
            $row = $Result->fetch_assoc();
            return $row["Id"];
        }
    }
    $mysqli->close();
}

So - that last function has an issue. I want to use the Id returned so that for example if it is 1, I display that content pertaining to Id 1 (multiple people will have that Id number as it is a tier system).

Basically - I have no idea why it isnt returning the Id to the original bit of code. I assume i've done something wrong. I just don't know how to fix it.

Echoing $row["Id"] will work so I know that bit is fine and its not an sql issue. But that isnt what I want to do.

  • 写回答

1条回答 默认 最新

  • drgbpq5930 2012-12-19 16:01
    关注

    You need to return the value from get_Account() in your is_Account() function:

    return $mysql->get_Account($currUser);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 阿里云python代码求解
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路