0

「google like」検索エンジンに問題があります。ページが読み込まれると、入力ボックス内の文字が結果の div 内に表示されることが期待されます。

入力ボックスに文字を入力せずにすべてのデータベースの内容を表示するにはどうすればよいですか? 以下に 3 つのファイルを示します。

索引.html

<html>
<head>
<title></title>
</head>
<body>
Caută analizele în baza noastră de date.<br>Taxa de urgență este de 35 Ron
<p align ="right">
<input type="text" id="go" class="field" name="go" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Caută analiza dorită':this.value;" value="Caută analiza dorită"/>
<input type="submit" name="search" id="submit" value="Cauta" /><br/>
<div id="search_query"></div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/instant.js"></script>
</p>
</body>
</html>

Search.php

<?php
$conn = mysql_connect("localhost","user","pass");

mysql_select_db("db");
mysql_set_charset("UTF8", $conn);
         

if(isset($_POST['search_query'])){
$search_query = mysql_real_escape_string(htmlentities($_POST['search_query']));


$search_query_x = explode(",",$search_query);   

foreach($search_query_x as $search_each){
@$x++;
if($x==1)
@$construct.="Den LIKE '%$search_each%'";
else
$construct.="AND Den LIKE '%s$search_each%'";
}
$construct ="SELECT * FROM biochimie1 WHERE $construct";
$run = mysql_query($construct) or die(mysql_error());
$foundnum = mysql_num_rows($run);
// Define $color=1
$color="1";
if ($foundnum==0){
echo "Ne pare rau dar nu există rezultate pentru <strong><font color='red'>$search_query</font></strong></br></br> Vă rugăm să verificați dacă ați scris corect";
}
else{
echo'<p align="center">';
echo "$foundnum \n";
echo ' rezultate găsite în urma căutării!</p>';
        echo "<table id='table1' border='0'width='500'>         
<tr>
<th width='150' align='center' valign='middle'>Denumire Analize</th>
<th width='50' align='center' valign='middle'>Preț</th>
<th width='100' align='center' valign='middle'>Zile de recoltare</th>
<th width='100' align='center' valign='middle'>Termen de eliberare a rezultatelor</th>
<th width='100' align='center' valign='middle'>Se poate lucra în regim de urgență</th>
</tr></table>";
while($runrows = mysql_fetch_assoc($run))
{
    $NrCrt = $runrows ['NrCrt'];
    $denanalize = $runrows ['Den'];
    $pret = $runrows ['Pret'];
    $rec = $runrows ['Rec'];
    $rez = $runrows ['Rez'];
    $obs = $runrows ['Obs'];
  echo "<table border='0'>";
  // If $color==1 table row color = #FFC600
if($color==1){
echo "
  <tr bgcolor='#efefef'>
    <td width='150' align='center' valign='middle'>$denanalize</td>
    <td width='50' align='center' valign='middle'>$pret</td>
    <td width='100' align='center' valign='middle'>$rec</td>
    <td width='100' align='center' valign='middle'>$rez</td>
    <td width='100' align='center' valign='middle'>$obs</td>
  </tr>
</table>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr bgcolor='#eaeaea'>
    <td width='150' align='center' valign='middle'>$denanalize</td>
    <td width='50' align='center' valign='middle'>$pret</td>
    <td width='100' align='center' valign='middle'>$rec</td>
    <td width='100' align='center' valign='middle'>$rez</td>
    <td width='100' align='center' valign='middle'>$obs</td>
  </tr>";
  // Set $color back to 1
$color="1";
}echo "
</table>";
}
}
}
else{
    echo 'An ERROR has occured';
}
?>

およびinstant.jsファイル

$('#go').keyup(function(){
                        var search_query=$(this).val();
                        $.post('search.php', {search_query: search_query},function(searchq){
                        $('#search_query').html(searchq);
                    });
});

よろしくお願いします。

4

1 に答える 1

1

ロード時に動作します:

$(document).ready(function(){
                        var search_query=$(this).val();
                        $.post('search.php', {search_query: search_query},function(searchq){
                        $('#search_query').html(searchq);
                    });
于 2013-02-12T14:18:03.217 に答える