gpt4 book ai didi

While 语句中的 If else 语句中的 PHP 多个变量

转载 作者:行者123 更新时间:2023-11-30 22:57:53 29 4
gpt4 key购买 nike

我开始一点一点地学习如何用 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()?

提前致谢

最佳答案

您需要在调用该函数时将其传递给该函数。见下文:

//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();
}
}
}

关于While 语句中的 If else 语句中的 PHP 多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25466667/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com