2012-11-04 42 views
0

一個搜索結果更加目前我的搜索腳本的作品,但它沒有這樣做,我想它做的事。目前它只返回一個搜索結果,即使應該爲搜索到的項目顯示大約20個搜索結果。我想弄清楚如何讓腳本返回應該顯示的那些缺失的結果。所以,也許這裏的專家能夠幫助:)顯示效果比用PHP

include('data.php'); 
    //Database Connection 
[email protected]_connect("$ip", "$user", "$pass") 
      or die(mysql_error()); 

//Select Database 
[email protected]_select_db($db, $con) 
      or die(mysql_error()); 


$search = $_POST['search']; 

$sql = mysql_query("select guid, name, staffmember, dateposted, id, admin_note from $whitelist where guid like '%$search%' or name like '%$search%' or staffmember like '%$search%' or dateposted like '%$search%' or id like '%$search%' or admin_note like '%$search%'"); 


while ($row = mysql_fetch_array($sql)) { 
    //Username 
    $name = $row['name']; 
    //GUID 
    $guid = $row['guid']; 
    //Staff Member Who Submitted 
    $staff = $row['staffmember']; 
    //ID 
    $id = $row['id']; 
    //Date Posted 
    $date = $row['dateposted']; 
    //Note From Admin 
    $admin = $row['admin_note']; 
    } 
    ?> 
    <html> 
    <body> 
    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table"> 
       <tr> 
        <!--<th class="table-header-check"><a id="toggle-all" ></a> </th>--> 
        <th class="table-header-repeat line-left minwidth-1"><a href="">ID</a> </th> 
        <th class="table-header-repeat line-left minwidth-1"><a href="">GUID</a></th> 
        <th class="table-header-repeat line-left"><a href="">Username</a></th> 
        <th class="table-header-repeat line-left"><a href="">Admin Note</a></th> 
        <th class="table-header-repeat line-left"><a href="">Staff Member</a></th> 
        <th class="table-header-repeat line-left"><a href="">Date Posted</a></th> 
        <th class="table-header-options line-left"><a href="">Options</a></th> 

       </tr> 
       <tr> 

        <td><?php echo "$id"; ?></td> 
        <td><?php echo "$guid"; ?></td> 
        <td><?php echo "$name"; ?></td> 
        <td><?php echo "$admin"; ?></td> 
        <td><?php echo "$staff"; ?></td> 
        <td><?php echo "$date"; ?></td> 
        <td class="options-width"> 
        <?php 
       echo '<a href="edit.php?id=' . $row['id'] . '" title="Edit" class="icon-1 info-tooltip"></a>'; 
       echo '<a href="delete.php?id=' . $row['id'] . '" title="Edit" class="icon-2 info-tooltip"></a>'; 
       ?> 

        </td> 
       </tr> 

       </table> 
       </body> 
       </html> 
+0

你提到你是第一次使用PHP。幫你一個忙,遠離'mysql_ *'函數並使用'mysqli_ *'或'PDO'來代替。請參閱:http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-function-in-php – h2ooooooo

回答

0

您需要輸出 「而($行= mysql_fetch_array($ SQL))」 循環中的數據。就像現在一樣,您的舊值將被覆蓋,以獲取每個新行。

在這種情況下,你的代碼已經被結構類似於

print out table header 
while ($row = mysql_fetch_array($sql)) { 
    print out table row 
} 
print out what comes after table 

include('data.php'); 
//Database Connection 
[email protected]_connect("$ip", "$user", "$pass") 
     or die(mysql_error()); 

//Select Database 
[email protected]_select_db($db, $con) 
     or die(mysql_error()); 


$search = $_POST['search']; 

$sql = mysql_query("select guid, name, staffmember, dateposted, id, admin_note from $whitelist where guid like '%$search%' or name like '%$search%' or staffmember like '%$search%' or dateposted like '%$search%' or id like '%$search%' or admin_note like '%$search%'");?> 


<html> 
<body> 
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table"> 
      <tr> 
       <!--<th class="table-header-check"><a id="toggle-all" ></a> </th>--> 
       <th class="table-header-repeat line-left minwidth-1"><a href="">ID</a> </th> 
       <th class="table-header-repeat line-left minwidth-1"><a href="">GUID</a></th> 
       <th class="table-header-repeat line-left"><a href="">Username</a></th> 
       <th class="table-header-repeat line-left"><a href="">Admin Note</a></th> 
       <th class="table-header-repeat line-left"><a href="">Staff Member</a></th> 
       <th class="table-header-repeat line-left"><a href="">Date Posted</a></th> 
       <th class="table-header-options line-left"><a href="">Options</a></th> 

      </tr> 


<?php 
while ($row = mysql_fetch_array($sql)) { 
//Username 
$name = $row['name']; 
//GUID 
$guid = $row['guid']; 
//Staff Member Who Submitted 
$staff = $row['staffmember']; 
//ID 
$id = $row['id']; 
//Date Posted 
$date = $row['dateposted']; 
//Note From Admin 
$admin = $row['admin_note']; 
?> 
      <tr> 

       <td><?php echo "$id"; ?></td> 
       <td><?php echo "$guid"; ?></td> 
       <td><?php echo "$name"; ?></td> 
       <td><?php echo "$admin"; ?></td> 
       <td><?php echo "$staff"; ?></td> 
       <td><?php echo "$date"; ?></td> 
       <td class="options-width"> 
       <?php 
} 

      echo '<a href="edit.php?id=' . $row['id'] . '" title="Edit" class="icon-1 info-tooltip"></a>'; 
      echo '<a href="delete.php?id=' . $row['id'] . '" title="Edit" class="icon-2 info-tooltip"></a>'; 
      ?> 

       </td> 
      </tr> 

      </table> 
      </body> 
      </html> 

(要好好和安全的代碼,幾件事情應該被改變,但是讓你開始,這應該工作)

+0

所以在這個意義上做到這一點 '而($行= mysql_fetch_array($ SQL)){ \t //用戶名 \t $打印=「​​$行[ '名稱'];? \t \t​​$行[ 'GUID']; \t \t $​​行[ 'staffmember']; \t \t $​​行[」 ID']; \t \t​​$ row ['dateposted']; \t \t​​$行[ 'admin_note'];「; \t}' – Ryahn

1
while ($row = mysql_fetch_array($sql)) { 
    //Username 
    $name = $row['name']; 
    //GUID 
    $guid = $row['guid']; 
    //Staff Member Who Submitted 
    $staff = $row['staffmember']; 
    //ID 
    $id = $row['id']; 
    //Date Posted 
    $date = $row['dateposted']; 
    //Note From Admin 
    $admin = $row['admin_note']; 
    } 

你在做什麼這裏是錯誤的。 在循環的每次迭代中,變量正在重新定義,它們的舊值正在被新值刪除和覆蓋。

+0

你會什麼建議?我仍然對PHP一般不熟悉......在此循環的每次迭代中, – Ryahn

+0

都會回顯您獲得的HTML值。 – Lior