dongluanjie8678 2015-11-30 03:55
浏览 117
已采纳

PHP中无法访问的语句

require_once 'C:/wamp/www/FirstWebsite/CommonFunctions.php';

function SelectRowByIncrementFunc(){
    $dbhose = DB_Connect();
    $SelectRowByIncrementQuery = "SELECT * FROM trialtable2 ORDER BY ID ASC LIMIT 1";
    $result = mysqli_query($dbhose, $SelectRowByIncrementQuery);
    $SelectedRow = mysqli_fetch_assoc($result);
    return $SelectRowByIncrementQuery;
    return $SelectedRow; //HERE is the error <-------------------------------
    return $result; 
}

$row = $SelectedRow;
echo $row;



if ($row['Id'] === max(mysqli_fetch_assoc($Id))){
    $row['Id']=$row['Id'] === min(mysqli_fetch_assoc($Id));#TODO check === operator
}
else if($row['Id']=== min(mysqli_fetch_assoc($Id))){
    $row['Id']=max(mysqli_fetch_assoc($Id));#TODO check === operator //This logic is important. DONT use = 1!

Ok, I am trying to write a program for the server end of my website using PHP. Using Netbeans as my IDE of choice I have encountered an error while attempting to write a function which will store a single row in an associative array. The issue arises when I try to return the variable $SelectedRow. It causes an 'Unreachable Statment' warning. This results in the program falling flat on its face. I can get this code to work without being contained in a function. However, I don't really feel that that is the way to go about solving my issues while I learn to write programs.

Side Notes: This is the first question I have posted on SO, so constructive criticism and tips are much appreciated. I am happy to post any specifications that would help an answer or anything else of the sort. I do not believe this is a so-called 'replica' question because I have failed to find another SO question addressing the same issue in PHP as of yet. If anybody has any suggestions about my code, in general, I'd be stoked to hear, as I have only just started this whole CS thing.

  • 写回答

2条回答 默认 最新

  • doushi1960 2015-11-30 03:58
    关注

    The return command cancels the rest of the function, as once you use it, it has served its purpose.

    The key to this is to put all of your information in to an array and return it at the end of the function, that way you can access all of the information.

    So try changing your code to this:

        require_once 'C:/wamp/www/FirstWebsite/CommonFunctions.php';
    
    function SelectRowByIncrementFunc(){
        $dbhose = DB_Connect();
        $SelectRowByIncrementQuery = "SELECT * FROM trialtable2 ORDER BY ID ASC LIMIT 1";
        $result = mysqli_query($dbhose, $SelectRowByIncrementQuery);
        $SelectedRow = mysqli_fetch_assoc($result);
        $returnArray = array();
        $returnArray["SelectRowByIncrementQuery"] = $SelectRowByIncrementQuery;
        $returnArray["SelectedRow"] = $SelectedRow;
        $returnArray["result"] = $result;
        return $returnArray;
    }
    

    And then you can access the information like so:

    $selectedArray = SelectRowByIncrementFunc();
    
    $row = $selectedArray["SelectedRow"]
    

    And so forth...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀