2013-07-22 39 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