2013-07-22 42 views
0

我有一個值的列表,在超鏈接'onclick'將在下面的數組中顯示關聯的記錄集。php onclick檢索數據集

通過PHP,我有連接表值工作的數據集。現在我需要將該數據集鏈接到onclick事件。

通過我的研究,我可以做幾件事:iFrames(似乎不推薦); JSON/AJAX(我不知道的語言以及我的其他數據都沒有使用這種構造,但可以使用直接PHP嗎?);

$ _GET變量與相關函數似乎是要走的路雖然我努力獲得正確的語法來創建一個響應。這是否會使用過濾器功能?

本質上:$ row_artistrecordset ['artist'] = $ row_getartists ['artist']。如果我可以將代碼基於這個匹配結構,它將有望在其他頁面中使用。

這是我到目前爲止的代碼:

<?php 
mysql_select_db($database_connectmysql, $connectmysql); 
$query_artistrecordset = "SELECT * FROM artists ORDER BY artist ASC"; 
$artistrecordset = mysql_query($query_artistrecordset, $connectmysql) or die(mysql_error()); 
$row_artistrecordset = mysql_fetch_assoc($artistrecordset); 
$totalRows_artistrecordset = mysql_num_rows($artistrecordset); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>artistindex</title> 
    <link href="exhibitstyles/exhibitstyles.css" rel="stylesheet" type="text/css" /> 
    </head> 
    <body>  
<?php include_once("exhibitstyles/header.php");?> 
<div id="singlemid" class="paragraph" style="text-align:center"> 
<div id="artistlist"> 
<?php do { ?> 
<a href=javascript:function_$_GET(artistindex.php?[$row_artistrecordset['artist']]);>; title="artistlink" class="list"><?php echo $row_artistrecordset['artist']; ?></a>&nbsp;| 
<?php } while ($row_artistrecordset = mysql_fetch_assoc($artistrecordset)); ?> 
</div> 
<br />  
<div id="searchresults"> 

function_$_GET(artistindex.php?[$row_artistrecordset['artist']]) { 
$.post("artistindex.php",'v=.$row_getartists['artist'].' + value, function $_GET(artistindex.php?[$row_artistrecordset['artist']]) { 
     $query_getartists.html().trigger("create"); 
}); 
} 

<?php 
mysql_select_db($database_connectmysql, $connectmysql); 
echo <a href=javascript:function_$_GET(artistindex.php?[$row_artistrecordset['artist']]);>.$row_getartists['artist'].; 
$query_getartists = "SELECT * FROM artists WHERE artist = '".$row_artistrecordset['artist']."' ORDER BY artist ASC"; 
$getartists = mysql_query($query_getartists, $connectmysql) or die(mysql_error()); 
     while ($row_getartists = mysql_fetch_assoc($getartists)) {    
       echo $row_getartists['artist'], "<br>"; 
       echo $row_getartists['website'], "<br>"; 
       echo $row_getartists['artist_statement'], "<br>"; 
       echo $row_getartists['image'], "<br>"; 
$artistlink = $row_getartists['artist']; 
$query_getseries = "SELECT * FROM series WHERE artist='$artistlink' ORDER BY exhibition ASC"; 
$getseries = mysql_query($query_getseries, $connectmysql) or die(mysql_error()); 
     while ($row_getseries = mysql_fetch_assoc($getseries)) { 
       echo $row_getseries['series'], "<br>"; 
       echo $row_getseries['exhibition'], "<br>"; 
       echo $row_getseries['series_statement'], "<br>"; 
       echo $row_getseries['image'], "<br>"; 
$serieslink = $row_getseries['series']; 
$query_getpieces = "SELECT * FROM pieces WHERE series='$serieslink'"; 
$getpieces = mysql_query($query_getpieces, $connectmysql) or die(mysql_error()); 
     while ($row_getpieces = mysql_fetch_assoc($getpieces)) { 
       echo $row_getpieces['piece'], "<br>"; 
       echo $row_getpieces['category'], "<br>"; 
       echo $row_getpieces['dimensions'], "<br>"; 
       echo $row_getpieces['price'], "<br>"; 
       echo $row_getpieces['description'], "<br>"; 
       echo $row_getpieces['image'], "<br>"; 
     } 
} 
?> 
</div> 
</div> 
</body> 
</html> 
<?php 
mysql_free_result($getartists); 

mysql_free_result($getseries); 

mysql_free_result($getpieces); 
     } 
?> 
+0

如果我這樣做完全錯了,請告訴我。我發現試圖實現類似目標的其他問題也沒有得到回答,因此很難知道這個邏輯有什麼問題。 – sarah369

+0

「onclick」定義了一個在單擊元素時將執行的Javascript函數。要做一些比如你想要的事情,需要改變爲另一個PHP腳本,它將生成新的頁面,或者更好的AJAX調用,它將刷新頁面上的數據而不重新加載它。查看jQuery,以真正簡單的方式使用AJAX。 – mlewis54

+0

對!所以我做錯了,不知情地使用js ......謝謝!這是我需要知道的! – sarah369

回答

0

你想,當用戶點擊一些動作發生。假設您有一張價值表,並且您想獲得有關價值的更多信息。在HTML可能是這樣的:

<table width=100% cellpadding=0 cellspacing=0> 
<tr> 
<td width=30% valign=top><span onclick="alert('Value 1 was clicked');">1</span></td> 
<td width=70% valign=top>Description of Value 1</td> 
</tr> 
<tr> 
<td width=30% valign=top><span onclick="alert('Value 2 was clicked');">1</span></td> 
<td width=70% valign=top>Description of Value 2</td> 
</tr> 
</table> 

什麼會發生在這裏的是,當你點擊任一表的最左邊的兩個列的JavaScript警告()函數將被調用。

您還可以將信息傳遞給自己的腳本,如:

<script> 
    function myOwnAlert(value) { 
     alert(value); 
    } 
    </script> 
<div id="myTable"> 
    <table width=100% cellpadding=0 cellspacing=0> 
    <tr> 
    <td width=30% valign=top><span onclick="myOwnAlert('Value 1 was clicked');">1</span></td> 
    <td width=70% valign=top>Description of Value 1</td> 
    </tr> 
    <tr> 
    <td width=30% valign=top><span onclick="myOwnAlert('Value 2 was clicked');">1</span></td> 
    <td width=70% valign=top>Description of Value 2</td> 
    </tr> 
    </table> 
</div> 

最終的效果是一樣的,被顯示一條消息。不過,您也可以使用jQuery動態更新表格。網上有很多關於jQuery的教程。你基本上會風與javascript功能,如:

<script> 
function myOwnAlert(value) { 
    $.post("getnewtable.php",'v=' + value, function(data) { 
      $("#myTable").html().trigger("create"); 
    }); 
} 
</script> 

這將導致你的表中的內容被替換爲您getnewtable.php腳本的輸出。

注意:這並不意味着成爲使用HTML或jQuery的主要例子 - 只是一個非常迷你的教程。

+0

好吧,所以關注最後一個例子,我把它作爲href「」並且這是正確的:function __ _ GET(artistindex.php?[$ row_artistrecordset ['artist']]){ $ .post(「 artistindex.php「,'v =。$ row_getartists ['artist']。'+ value,function $ _GET(artistindex.php?[$ row_artistrecordset ['artist']]){query_getartists.html()。trigger 「創建」); }); – sarah369

+0

我認爲這樣的'如果''其他'構造是PHP?我很疑惑什麼是PHP和什麼是java之間的界限... – sarah369

+0

如果您要使用javascript,我不會使用href,這就是爲什麼我用標籤包圍值。它會更像是:function getArtistIndex(v){then the $ .post call)} onclick調用觸發你的javascript函數,然後調用一個php腳本。如果/ else構造以多種語言出現。 標籤之間的代碼是javascript(不是java)。在我的例子中沒有PHP,只是JavaScript和HTML。 – mlewis54