我开始逐步学习如何用PHP编程。但我遇到了一个我无法解决的问题。所以我需要一些帮助。问题是,在我的函数中,我从数据库中获取信息。变量$ DisplayProducts01Title我想用到我在
下面发布的其他函数中获取数据的功能:
//GetAllPages
function GetAllPages() {
$GetAllPagesSql = "SELECT ContentPages.ContentPagesID, ContentType.ContentTypeName, ContentInformation.ContentInformationTitle, ContentPages.ContentPagesOrder FROM `ContentPages` INNER JOIN ContentType ON ContentPages.ContentTypeID = ContentType.ContentTypeID INNER JOIN ContentInformation ON ContentPages.ContentInformationID = ContentInformation.ContentInformationID ORDER BY ContentPagesOrder";
$GetAllPagesQuery = mysql_query($GetAllPagesSql);
while (($GetAllPagesRow = \mysql_fetch_assoc($GetAllPagesQuery)) != false) {
if($GetAllPagesRow[ContentTypeName] == 'products01') {
DisplayProducts01DesignFunction();
$DisplayProducts01Title = $GetAllPagesRow[ContentTypeTitle];
return $DisplayProducts01Title;
}
else if ($GetAllPagesRow[ContentTypeName] == 'information01') {
DisplayInformation01DesignFunction();
}
}
}
显示数据的功能:
//DisplayProductsDesignFunction
function DisplayProducts01DesignFunction($DisplayProducts01Title) {
echo "<div class='paddingcnt' id='services'>
<div class='row-fluid'>
<div class='span12'>
<div class='pricing'>
<div class='container'>
<div class='row-fluid'>
<h1>" . $DisplayProducts01Title . "</h1>
<div class='row-fluid'>";
DisplayProducts01Function();
echo "</div>
</div>
</div>
</div>
</div>
</div>
</div>";
}
如何将函数GetAllPages()中的变量$ DisplayProducts01Title用于函数DisplayProducts01DesignFunction()?
提前致谢
答案 0 :(得分:0)
调用它时需要将其传递给该函数。见下文:
//GetAllPages
function GetAllPages() {
$GetAllPagesSql = "SELECT ContentPages.ContentPagesID, ContentType.ContentTypeName, ContentInformation.ContentInformationTitle, ContentPages.ContentPagesOrder FROM `ContentPages` INNER JOIN ContentType ON ContentPages.ContentTypeID = ContentType.ContentTypeID INNER JOIN ContentInformation ON ContentPages.ContentInformationID = ContentInformation.ContentInformationID ORDER BY ContentPagesOrder";
$GetAllPagesQuery = mysql_query($GetAllPagesSql);
while (($GetAllPagesRow = \mysql_fetch_assoc($GetAllPagesQuery)) != false) {
if($GetAllPagesRow[ContentTypeName] == 'products01') {
// changes start here
$DisplayProducts01Title = $GetAllPagesRow[ContentTypeTitle];
DisplayProducts01DesignFunction($DisplayProducts01Title);
// changes end here
}
else if ($GetAllPagesRow[ContentTypeName] == 'information01') {
DisplayInformation01DesignFunction();
}
}
}