如何从数据库表和输出数组中获取值,以便在 Concrete5 5.8 中以 Formify 形式使用



我对要从数据库填充的数组没有太多经验。

在我的控制器中,我有

$db = Database::connection('esco_web_connection');
$dynamicStates = $db->executeQuery('SELECT * FROM Products_Premiums ');
$this->set('dynamicState', $dynamicStates);

在我看来,我有...

foreach($dynamicStates as $dynamicState){
echo $dynamicState . "<br>";
}

但是,我得到的只是....

Array
Array
Array
Array
etc....

我在这里不知所措。 我需要所有数据才能在表单下拉列表中设置条件数据。 但是,我无法显示任何数据。

当我print_r时,我看到...

Array ( [wpp_UID] => 738452 [wpp_UpdateDate] => 2019-09-16 [wpp_ProductNumber] => 2-48 [wpp_MfrNumber] => 2 [wpp_MfrName] => Widex Hearing Aid Company [wpp_Model] => Inteo- ITC [wpp_Model2] => [wpp_State] => [wpp_PricingName] => Protection Plus [wpp_PricingStyle] => ITC [wpp_StateDefaultAnnual] => 201 [wpp_StateDefaultMonthly] => 18 [wpp_Channel] => Earserv ) Array ( [wpp_UID] => 738453 [wpp_UpdateDate] => 2019-09-16 [wpp_ProductNumber] => 2-47 [wpp_MfrNumber] => 2 [wpp_MfrName] => Widex Hearing Aid Company [wpp_Model] => Inteo- CIC [wpp_Model2] => [wpp_State] => [wpp_PricingName] => Protection Plus [wpp_PricingStyle] => CIC [wpp_StateDefaultAnnual] => 223 [wpp_StateDefaultMonthly] => 20 [wpp_Channel] => Earserv ) Array ( [wpp_UID] => 738454 [wpp_UpdateDate] => 2019-09-16 [wpp_ProductNumber] => 2-50 [wpp_MfrNumber] => 2 [wpp_MfrName] =>

试试这个

<?php 
$db = Database::connection('esco_web_connection');
$dynamicState = $db->executeQuery('SELECT * FROM Products_Premiums');
$this->set('dynamicState', $dynamicState);
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<label for="state">State</label>
<select name="state" id="state">
<option value="" selected="selected">Please Select</option>
<?
foreach($dynamicState as $dynamicStates) { ?>
<option value="<?= $dynamicStates['wpp_State'] ?>"><?= $dynamicStates['wpp_State'] ?></option>
<?
} ?>
</select> 
<label for="manufacturer">Manufacturer</label>
<select name="manufacturer" id="manufacturer">
<option value="" selected="selected">Please Select</option>
</select>
<script type="text/javascript">
$(document).ready(function () {
$('#state').change(function() {
var sel_state = $(this).val();
.ajax({
type: "POST",
url: "fetch_mfrName.php",
data: 'state=' + sel_state,
success: function(result-array) {
var result = JSON.parse(result-array);
result.each(function(){
$('#manufacturer').append('<option value="'+result['wpp_MfrName']+'">'+result['wpp_MfrName']+'</option>');
});
$('#manufacturer').change(function() {
////...next ajax if you need
});
} 
});
}); 
}); 
</script>
</body>
</html>

创建一个 php 文件,文件名为 'fetch_mfrName.php'

<?php    
include 'connect_to_db.php';
$state = mysql_real_escape_string($_POST['state']);
$query = "SELECT `wpp_MfrName` FROM `Products_Premiums` WHERE `wpp_State`='$state'";
$mfr_names = mysql_query($query);
echo mysql_fetch_assoc($mfr_names);
?>

相关内容

  • 没有找到相关文章

最新更新