简体   繁体   中英

Php/Html form with different option selection

my php and html coding is:

$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, 0, $damt2); //array_slice — Extract a slice of the array

Table

<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{
    }
}
?>

Why in results all blank ?

I guess where i'm doing mistake : In foreach loop by both values are continued. In category selection with radio button.

I want form with two options ( one with search number 50,100,200 ) and second with category like " cow " and " chicken " .

My question is solved now and i did it by reading several posts from all around the internet and at the end i tried :

IN HTML section:

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

PHP coding :

<?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{
 }
}

In the results, i have two radio buttons and pulldown menu to select length(50,100,200..etc) of result with desire category (Chicken/Cow). thank you all for trying to support me with your suggestions. Have good day to all ^_^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM