-1

何の助けにもならないので、質問の説明を変えるかもしれませんが、本当に助けが欲しいです。ユーザーがmysqlテーブルの学生データを検索できるようにする検索ボックスがフォームにあり、単一のフィールドの検索にしか成功しません。たとえば、(姓または名または姓)私にとって大きな問題は、同じテキスト入力フィールドまたは任意の数のテキスト入力フィールド (text1、text2、text3) だけが必要なのは、正確な結果を得ることです。間違いがあればごめんなさい。

ここでは、単一フィールド検索を取得するために使用する php コードを示します。

<html>
<head></head>
<body><input type="text" name="query" value=""/>
     <input name="submit" type="submit" value="Search" />

     <?php
     $query="query";

//mysql_connect

$query='query';
if (isset($_GET['query'])) 
    {    
        $query=$_GET['query'];

        // Instructions if $_POST['value'] exist    
    } 

$raw_results = mysql_query("SELECT * FROM stdreg_exam 
                  WHERE (`fname` LIKE '%".$query."%') or (`secname` LIKE '%".$query."%')or  
                     (`date` LIKE '%".$query."%') or (`surname` LIKE '%".$query."%')") or  
    die(mysql_error());


$raw_results2 = mysql_query("SELECT(idnumber) FROM student 
                           WHERE (`fname` LIKE '%".$query."%') or (`secname` LIKE  
                            '%".$query."%') or (`date` LIKE '%".$query."%')or    
                              (`surname` LIKE '%".$query."%')") or die(mysql_error());  


// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table

// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'

if(mysql_num_rows($raw_results) > 0){ 
    // if one or more rows are  
    returned do following


                    while($results = mysql_fetch_array($raw_results)){
                        while($results2 = mysql_fetch_array($raw_results2)){

                            // $results = mysql_fetch_array($raw_results) puts data from database into  
                            array, while it's valid it does the loop

    echo "<table width='750' height='5' cellpadding='2'  
                                         cellspacing='0' border='0'>";
echo"<tr><td>Std_id</td><td>Mathematics</td><td>English</td> 
               <td>Kiswahili</td><td>Geograph</td><td>Ict</td><td>Science</td> 
                <td>History</td><td>Pds</td><td>V skill</td><td>French</td> 
                 <td>Religion</td><td>Civics</td>";
echo "<h4>&nbsp;".$results['exam_name']."&nbsp; Examination result for   
                  &nbsp;" .$results['fname']."&nbsp;" .$results['secname']  
."&nbsp;".$results['surname']."&nbsp;".$results['class']."&nbsp;Class"."&nbsp;        
                      held on</p>".$results['date']."<hr><th>"; echo"<tr>";

echo ""."<td>".$results2['idnumber'].""."<td>".$results['mathematics']."%"." 
               <td>".$results['english']."%"."<td>".$results['kiswahili']."%"."  
               <td>".$results['geograph']."%"."<td>".$results['ict']."%"."
               <td>".$results['science']."%"."<td>".$results['history']."%"." 
               <td>".$results['pds']."%"."<td>".$results['vskill']."%"." 
               <td>".$results['french']."%"."<td>".$results['religion']."%"." 
               <td>".$results['civics']."%"."</td></p>";echo"</table>";                
//posts results gotten from database(title and text) you can also show id  
($results['id'])
}

}
}
               else{ 
                   // if there is no matching rows do following
                   echo "No such information in School database";
               }

}
                     else{ 
                         // if query length is less than minimum
                         echo "Enter more strings!!!Minimum length is ".$min_length; "Charactes";
                     }

?>
4

2 に答える 2