gpt4 book ai didi

php - 使 PHP 函数相互协作

转载 作者:行者123 更新时间:2023-11-28 02:55:46 25 4
gpt4 key购买 nike

我正在构建一个网页,使用户能够查看有关他们选择的特定产品的报告。步骤如下:

用户选择界面(测试版或云)-> 用户选择产品(产品基于所选界面。)-> 相应地显示信息。

显示信息的页面写法如下:

HTML

<div class="roundiv" >

<h4>*Interface: </h4>
<select class="form-control " style='width:250px;' onclick="INSERT SOMETHING HERE" >
<option value="-1" >Select Interface </option>
<?php
config::selectInterface($cao);
?>

</select>

<h4>
*Product:
</h4>
<select class="form-control" style="width:250px;">
<option value="-1" >Select Product</option>
<?php
config::selectIntProduct($cao);
?>
</select>
<button class="btn btn-success " value="Submit" onclick="" style="margin-left: auto; display:block;" > Submit </button>
<!-------------INFO WILL BE DISPLAYED HERE------------->
</div>

我已经开始在配置类中编写函数,并希望继续使用这种方法。

这是我在配置类中写的函数:

函数 1

public static function selectInterface(CGenDb $cao) {

$sel_interface_options = new CGenRS("select type_desc, type_id from lu_type where type_status = 't' and type_group = 'cloud' and type_sub_group = 'db'", $cao);
$sel_interface_options->first();
if ($sel_interface_options->rowcount()) {
while (!$sel_interface_options->eof()) {
echo "<option value='" . $sel_interface_options->valueof('type_id') . "'>" . $sel_interface_options->valueof('type_desc') . "</option>";
$sel_interface_options->next();
}
}
$interface_bool = True;
return $interface_bool;
}

selectIntProducts 类看起来像这样:

功能 2

public static function selectIntProduct(CGendb $cao,$selected_interface){

$selected_interface=$cao_interface= "The interface ID"

$sel_product_options = new CGenRS("select prod_name, prod_id from lu_products where prod_active = 't'", $cao_interface);
$sel_product_options->first();

if ($sel_product_options->rowcount()) {
while (!$sel_product_options->eof()) {
echo "<option value='" . $sel_product_options->valueof('prod_id') . "'>" . $sel_product_options->valueof('prod_name') . "</option>";
$sel_product_options->next();
}
}
}

这就是我需要帮助的地方:

  1. 我只想在选择/选择接口(interface)时显示产品选择器。(我的想法是从函数 1 返回 $interface_bool,测试它是否为真是,显示下一节。)

  2. 函数 1 中选择的值应该是函数 2 中的 $selected_interface

我怎样才能做到这一点?

最佳答案

你只能用php来实现,当你重新加载页面并将选择的界面发送回php时。

更好更方便的方法是使用 javascript 来填充选择,为此我建议使用 knockout.js .它有很好的文档可供遵循。

对于 php,我建议这样做:

<div class="roundiv" >
<h4>*Interface: </h4>
<select class="form-control " style='width:250px;' onchange="document.location.href='https://url-to-same-page&interface=' + this.options[this.selectedIndex].value" >
<option value="-1" >Select Interface </option>
<?php
config::selectInterface($cao, $_GET['interface']);
?>

</select>

<?php if (!empty($_GET['interface'])): ?>
<h4>
*Product:
</h4>
<select class="form-control" style="width:250px;">
<option value="-1" >Select Product</option>
<?php
config::selectIntProduct($cao, $_GET['interface']);
?>
</select>
<button class="btn btn-success " value="Submit" onclick="" style="margin-left: auto; display:block;" > Submit </button>
<!-------------INFO WILL BE DISPLAYED HERE------------->

<?php endif; ?>
</div>

同时更新 selectInterface 以包含选定的界面:

public static function selectInterface(CGenDb $cao, $selected_interface) {
// ... code
while (!$sel_interface_options->eof()) {
echo "<option value='" . $sel_interface_options->valueof('type_id') . "' "
. ($selected_interface == $sel_interface_options->valueof('type_id') ? 'selected="selected"' : '')
. ">" . $sel_interface_options->valueof('type_desc') . "</option>";
$sel_interface_options->next();
}
// .. code continues
}

关于php - 使 PHP 函数相互协作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37184438/

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