我有一個小問題。我使用本教程基於數據庫值創建onclick表
http://www.codemashups.com/dynamic-search-filtering-using-jquery-and-php/
它讓我搜索我的數據庫,並在表中返回結果。 這是在網頁「搜索data.php」代碼的基礎
if ($conn) {
/* Fetch the users input from the database and put it into a
valuable $fetch for output to our table. */
$fetch = mysql_query("SELECT * FROM clients
WHERE client_name LIKE '%{$param}%' OR client_email REGEXP '^$param' OR client_address LIKE '%{$param}%' OR client_postcode LIKE '%{$param}%' OR client_phone REGEXP '^$param'");
/*
Retrieve results of the query to and build the table.
We are looping through the $fetch array and populating
the table rows based on the users input.
*/
while ($row = mysql_fetch_object($fetch)) {
$sResults .= '<tr id="'. $row->id . '" >';
$sResults .= '<td>' . $row->client_name . '</td>';
$sResults .= '<td>' . $row->client_email . '</td>';
$sResults .= '<td>' . $row->client_address . '</td>';
$sResults .= '<td>' . $row->client_postcode . '</td>';
$sResults .= '<td>' . $row->client_phone . '</td>
</tr>';
}
}
/* Free connection resources. */
mysql_close($conn);
/* Toss back the results to populate the table. */
echo $sResults;
這一切工作正常,並用我的表,我可以搜索並顯示我想你問的信息,太棒了!那你想要什麼?
那麼,我的表是一個商店的客戶端信息,而在以前沒有可搜索的表格中,您從列表中點擊您想要的客戶端,然後轉到其所有信息頁面(列表中的信息僅限於姓名和地址,因爲整個頁面有電話,郵政編碼等),並使用onclick。
因此,這裏是我的新搜索表的表:
<table>
<tr>
<th class="ui-state-default">Name</th>
<th class="ui-state-default">Email</th>
<th class="ui-state-default">Address</th>
<th class="ui-state-default">Postcode</th>
<th class="ui-state-default">Phone</th>
</tr>
<tbody id="results" onclick="location='../clients.php?action=viewClient&clientId=<?php echo ?>'" ></tbody>
</table>
就像我說的它的偉大工程,所有的客戶信息來了,但我需要有「身份證」之間搞出在onclick線上的回聲(我想如果它顯示正確的ID不需要回聲)。
onclick="location='../clients.php?action=viewClient&clientId=<?php echo ?>
因此,誰能看到一個簡單的方法來獲取ID進入的onclick的信息,我試圖創建的「搜索data.php」頁面<tr>
部分的點擊數,但它沒有工作要麼因爲它不會,要麼我做錯了,後來我在想。
反正任何幫助將是偉大的。
--------------------編輯------------------------- -
我發現我可以創建一個有效的鏈接。我可以創建這樣的結果的鏈接:
$sResults .= '<td><a href="../clients.php?action=viewClient&clientId='. $row->id .'">'. $row->client_name .'</a></td>';
此創建一個工作環節,但是當我嘗試做了類似的事情的onclick它甚至不去任何地方,更不用說正確的地方,如如果它不喜歡這樣做,如果這有助於任何人進一步處理好的onclick問題。
您是否創建了一個可以生成表格的php頁面? – 2013-03-22 16:30:52
你應該簡單地使用真實的鏈接... – soju 2013-03-22 16:30:55
我不使用真正的鏈接,我有一個名爲viewClient的頁面,它是基於id動態填充的,所以如果鏈接中的id是8,將顯示不同用戶的詳細信息如果它是1 – snookian 2013-03-22 16:35:19