gpt4 book ai didi

php - 使用带有 switch 功能的 foreach

转载 作者:行者123 更新时间:2023-11-29 07:44:09 24 4
gpt4 key购买 nike

我的数据库有一个表,该表返回站点中的部分,问题不是返回数据库中的第一个注册表,这里是代码:

$mysqli = $conexion_temporal; //connect to mysqli
$queryn = $mysqli->query('select * from sections'); //we get the content
$dataset = array(); //we declare an array
while ($data = $queryn->fetch_array()) {
$dataset['seo'] = $data['seo'];
}



switch ($pagina) { //switch the sections
case 'compra_completa':
echo $plantilla->SuccessPurchase();
break;
case $dataset['seo']: //the seo column of the database
echo $plantilla->album($dataset['seo'],$subcat);
$subcat = $_GET['subcat']; //if we request category we show ..
break;
}

问题是没有获取数据库的第一列 http://prntscr.com/60gjzd

编辑:仅适用于最后插入的数据

最佳答案

$dataset['seo'] 总是会被 $data['seo'] 覆盖,这就是为什么你只能获取最后插入的数据

$dataset['seo'] = $data['seo'];

如果您需要将所有数据存储到数据集,您应该使用 array_push

while ($data = $queryn->fetch_array()) {    
array_push($dataset,$data['seo']);
}

据我了解,这些是你想要的吗?

$mysqli = $conexion_temporal; //connect to mysqli
$queryn = $mysqli->query('select * from sections'); //we get the content
$dataset = array(); //we declare an array

//find section
$matched_section = false;

while ($data = $queryn->fetch_array()) {
array_push($dataset,$data['seo']);

//if section match store as $matched_section
if($data['seo'] == $pagina)
$matched_section = $data['seo'];
}

if($pagina == 'compra_completa'){
echo $plantilla->SuccessPurchase();
}else if( matched_section ){
echo $plantilla->album(matched_section,$subcat);
$subcat = $_GET['subcat']; //if we request category we show ..
}else{
........
}

关于php - 使用带有 switch 功能的 foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28292648/

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