繁体   English   中英

谁能帮助我要求工作?

[英]Can anyone help me to make require working?

所以我有2个php文件,一个正在调用函数,另一个正在实现函数。

在实现函数的过程中,我称之为require(“ shares.php”)-shares.php是调用函数的文件

问题在于,它没有看到功能,因此我进行了检查以查看功能是否存在,并且不,它们不存在((。

请看这里。

shares.php

    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> 
<html xmlns='http://www.w3.org/1999/xhtml'> 
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> 
<title>Shares</title> 
</head> 

<body> 
<?php

if (function_exists('get_contents')) 
{ 
    if(function_exists('print_contents'))
    {
        $data = get_contents();
        print_contents($data);
    }
}

else
{
    print("Not Found");
}
?>
</body> 
</html> 

这里是功能的实现。

       if(isset($_GET['share']))
        {
            $conn = db_connect();
            if($_GET["newSorting"] == 1)
            {

                 $shares = get_shareSearch($conn, "company");

            }

            if($_GET["newSorting"] == 2)
            {

                $shares = get_shareSearch($conn, "rate");

            }
            if($_GET["newSorting"] == 3)
            {

                 $shares = get_shareSearch($conn, "issue_date");

            }

            db_disconnect($conn);
            $contents = array('shares' => $shares);
            return $contents;
        }

        else
        {
            $conn = db_connect();
            $shares = get_share($conn);
            db_disconnect($conn);
            $contents = array('shares' => $shares);
            return $contents;
        }

    }

    function print_contents($contents) 
    {

        if(count($contents['shares']) == 0)
        {
            echo "<script type = 'text/javascript'>alert('Sorry but share is not found! Q_Q');</script>";

        }
        else
        {
        ?>    
            <table>
                <tr>
                    <th><a href="share-company-links.php?companySort=true">Company Name</a></th>
                    <th><a href="share-company-links.php?rateSort=true">Rate</a></th>
                    <th><a href="share-company-links.php?issueSort=true">Issue date</a></th>
                </tr>
        <?php

        foreach ($contents['shares'] as $share) 
        {
            print "<tr>";
            $identifier = urlencode($share['COMPANY']);
            print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
            print "<td>{$share['RATE']}</td>";

            $issue_date = $share['ISSUE_DATE'];
            $issue_date = $issue_date === NULL ? "&lt; not available &gt;" : $issue_date;
            print "<td>{$issue_date}</td>";
            print "</tr>";
        }
        ?>
            </table>
        <?php
        }
    }

    require_once("shares.php");

    ?>

结果将是Not Found

使用这些功能的文件(share.php)应该require其他文件,而不是其他文件。 所以,在股份

<body> 
<?php

require_once('thatotherfile.php');

if (function_exists('get_contents')) 
{ 
    if(function_exists('print_contents'))
    {
        $data = get_contents();
        print_contents($data);
    }
}

将工作。

您可以使用, include("otherfile.php") require("otherfile.php") include_once("otherfile.php")require_once("otherfile.php")使用 ,而不是 功能的文件具有功能的文件 ,即:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> 
<html xmlns='http://www.w3.org/1999/xhtml'> 
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> 
<title>Shares</title> 
</head> 

<body> 
<?php
include_once("otherfile.php");
//the rest of the code...

http://php.net/manual/zh/function.include.php
http://php.net/manual/zh/function.require.php
http://php.net/manual/zh/function.include-once.php
http://php.net/manual/zh/function.require-once.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM