4

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 " .

6
  • Have you started the session? Commented May 18, 2015 at 11:59
  • Please use <?php instead of <?. if you use <? php.ini --->short_opentag=On Commented May 18, 2015 at 12:00
  • Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); Commented May 18, 2015 at 12:02
  • yes session starts again ! and please have a look what my table is showing in results . prntscr.com/76kabe Commented May 18, 2015 at 12:10
  • 1
    Just asking ( don't know if this one is suitable ) " if(!isset($_POST['cow'])){ if ($uInfo["keyword"] != 'cow') continue; } " how to use it ? @JayBlanchard Commented May 18, 2015 at 13:04

1 Answer 1

3

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 ^_^

Sign up to request clarification or add additional context in comments.

1 Comment

helpful for me too @Fake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.