2016-07-29 7 views
-1

私は検索オプションを作成しています。ユーザーが都市名を入力し、その都市に住んでいる人の詳細を表示します。または、ユーザーはすべての人物を見るためにブランク入力を残すことができます。ディレクトリからPHPを検索する

このコードではエラーは発生していません。すべてのPHPバリデーターを確認しました。

$show_grile = 'Y'; 

$show_grilYに設定し、それを行うだけの行は、変数名をmisspellsされている場合、スクリプトのみ何かを出力します。しかし、これは何も出力

<?php 
$find_city = $_POST['find']; //form 

//if user input nothing see all file    

if (empty($find_city)) 
    { 
     $find_city = 'ALL'; 
    } 

//directory open 
$dirname = "gimg"; 
     $dirhandle = opendir($dirname); 

     if($dirhandle) 
     { 
      $gimgs = array(); 

      while (false !==($file = readdir($dirhandle))) 
      { 
       if ($file != "." && $file != "..") 
       { 
        array_push($gimgs , $file); 
       } 
      } 
     } 

     sort($gimgs); 

     // I think problem in this foreach 

     foreach($gimgs as $elm) 
     { 
      displayPropertyInfo($elm, $find_city); 
     } 

    //funtion Definitions 

    function displayPropertyInfo($elm, $find_city) 
    { 

     $img_name = 'gimg/'.$elm; 
     $g_img = "<img src='".$img_name."'>"; 

     //filename type changing from one directory to another 

     $g_info = str_replace('.jpg' , '.txt', $elm); 

     $filename = 'ginfo/'.$g_info; 

     $fp = fopen($filename, 'r'); 

     $show_gril = 'Y'; 

     //search function 

     while(true) 
     { 
      $line = fgets($fp); 

      if (feof($fp)) 
      { 
       break; 
      } 

      $pos = stripos($line, 'City:'); 

      if ($pos !== false) 
      { 
       $city = substr($line,5); 
       $city = trim($city); 

       if ($find_city != 'ALL') 
       { 
        $subpos = stripos($city,$find_city); 

        if($subpos === false) 
        { 
         $show_gril = 'N'; 
         break; 
        } 
       } 
      } 
      //checking 
      $pos = stripos($line,'Name:'); 

      if ($pos !== false) 
      { 
       $name = substr($line, 5); 
       $name = trim($name); 
      } 

      $pos = stripos($line,'Age:'); 

      if ($pos !== false) 
      { 
       $age = substr($line, 4); 
       $age = trim($age); 
      } 
      $pos = stripos($line,'Price:'); 

      if ($pos !== false) 
      { 
       $price = substr($line, 6); 
       $price = trim($price); 
      } 
      $pos = stripos($line,'Description:'); 

      if ($pos !== false) 
      { 
       $description = substr($line, 12); 
       $description = trim(description); 
      } 

     } 

     if($show_gril == 'Y') 
     { 
      print $g_img; 

      print "City: ".$city."<br/>"; 
      print "Name: ".$name."<br/>"; 
      print "Age: ".$age."<br/>"; 
      print "Price: ".$price."<br/>"; 
      print "Description: ".$description."<br/>"; 
     } 
    } 
?> 
+0

*「このコードではエラーは表示されません。すべてのPHPバリデーターを確認しましたが、これは何も出力しません」* - 未定義の変数はチェックしていません。 「テスト」コードではなく、アダムからそのことを知らない。構文エラーがあるため何も出力しません。 –

+0

とこの '$ _POST ['find']'はあなたに値が入っているかどうかを知っています。 –

+0

本当に仲良く!あなたはまだPHPをコードしていない、と思います。 – imran

答えて

0

ここで問題のあるラインですません。あなたが最後にEを取り除くとうまくいくはずです。

+0

ありがとうございますが問題はありませんか? – imran

+0

foreachの問題 – imran

関連する問題