0
<?php   

 function get_subject_by_id2() {
            global $connection;
            $query = "SELECT * ";
            $query .= "FROM subjects ";
            $query .= "WHERE id= 2 ";
            $query .= "LIMIT 1";
            $result_set = mysqli_query($connection, $query);
            confirm_query($result_set);
            // REMEMBER:
            // if no rows are returned, fetch_array will return false
            if ($subject = mysqli_fetch_array($result_set)) {
                return $subject2;
            } else {
                return NULL;
            }
        }


echo $subject2['content1'];
echo $subject2['content2'];

?>

我不知道为什么这不起作用。请帮忙!

我相信它不会返回 NULL,而是返回 $subject2。由于某种原因,它不起作用。

4

1 回答 1

2

您甚至在哪里调用该函数?该函数没有被调用,因此它不能返回任何东西

$subject2=get_subject_by_id2();   // forgot to make this call?
echo $subject2['content1'];
echo $subject2['content2'];

也正如yajakass所建议的那样修复错字

于 2013-01-03T20:31:32.173 回答