加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

具有不同选项选择的Php / Html表单

发布时间:2020-12-13 16:56:34 所属栏目:PHP教程 来源:网络整理
导读:我的php和html编码是: $damt2 = isset($_POST['damt2']) ? $_POST['damt2'] : 200;$dateinfo2 = json_decode(file_get_contents($_SESSION['base_path'] . 'dl.dict'),true);arsort($dateinfo2); //arsort — Sort an array in reverse order and maintain
我的php和html编码是:

$damt2 = isset($_POST['damt2']) ? $_POST['damt2'] : 200;
$dateinfo2 = json_decode(file_get_contents($_SESSION['base_path'] . 'dl.dict'),true);
arsort($dateinfo2); //arsort — Sort an array in reverse order and maintain index association
$dateinfo2 = array_slice($dateinfo2,$damt2); //array_slice — Extract a slice of the array

<input type="hidden" name="userId" value="<?= $_SESSION['userId']; ?>">
<select name="damt2" onchange="this.form.submit()">
<option value="50" <?= (isset($damt2) & $damt2 == 50) ? 'selected' : ''; ?>>50</option>
<option value="100" <?= (isset($damt2) & $damt2 == 100) ? 'selected' : ''; ?>>100</option>
<option value="200" <?= (isset($damt2) & $damt2 == 200) ? 'selected' : ''; ?    >>200</option>

<input name="radio" type="radio" value="cow">Cow
<input name="radio" type="radio" value="chicken">Chicken
</select>  <input type="submit" name="submit" value="Show List & Save">

<?php    
    foreach ($dateinfo2 as $key => $time){
    $uInfo = $_SESSION['data']->table('units')->byName($key)->data();
    if ($uInfo["keyword"] != 'chicken') continue;
    if ($uInfo["keyword"] != 'cow') continue;
    if (isset($uInfo['type']) && !empty($uInfo['type'])) {
        echo '<center><font color="olive">TypE: '.$uInfo['type'].'</font><br>';
    }else{
    }
}
?>

为什么结果全都空白?

我猜我在哪里做错了:
在foreach循环中,两个值都继续.
在带有单选按钮的类别选择中.

我希望表格有两个选项(一个搜索号为50,100,200),第二个类别为“牛”和“鸡”.

解决方法

我的问题现在已经解决,我通过阅读互联网上的几个帖子来做到这一点,最后我尝试了:

在HTML部分:

<input name="cow" type="radio" >Cow
<input name="chicken" type="radio" >chicken

PHP编码:

<?php
 foreach ($dateinfo2 as $key => $time)
{
  $uInfo = $_SESSION['data']->table('units')->byName($key)->data();//item get data by name

  if(isset($_POST['cow'])){
    if ($uInfo["keyword"] != 'cow') continue;
}
  if(isset($_POST['chicken'])){
    if ($uInfo["keyword"] != 'chicken') continue;
}
if (isset($uInfo['type']) && !empty($uInfo['type'])) {
    echo '<center><font color="olive">TypE: '.$uInfo['type'].'</font><br>';
}else{
 }
}

在结果中,我有两个单选按钮和下拉菜单来选择愿望类别(鸡/牛)的结果长度(50,200..etc).谢谢大家试图支持我的建议.祝所有人都有美好的一天^ _ ^

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读