0

我有一个值列表,通过超链接“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);
      }
?>
4

1 回答 1

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 alert() 函数。

您还可以将信息传递给您自己的脚本,如下所示:

    <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 的主要示例——只是一个非常迷你的教程。

于 2013-07-22T01:11:50.517 回答