hyperlink - php onclick to retrieve dataset -
i have list of values upon hyperlink 'onclick' display associated recordset in array below.
through php, have dataset of connected table values working. need link dataset onclick event.
through research there few ways can go this: iframes (seems not recommended); json/ajax (languages not know , none of other data uses construct, possible use straight php?);
$_get variable related function seems way go though struggling right syntax create response. using filter function?
essentially: $row_artistrecordset['artist'] = $row_getartists['artist']. if can base code on match construct versatile enough use in other pages.
this code far:
<?php mysql_select_db($database_connectmysql, $connectmysql); $query_artistrecordset = "select * artists order 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 { ?> <a href=javascript:function_$_get(artistindex.php?[$row_artistrecordset['artist']]);>; title="artistlink" class="list"><?php echo $row_artistrecordset['artist']; ?></a> | <?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 * artists artist = '".$row_artistrecordset['artist']."' order 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 * series artist='$artistlink' order 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 * pieces 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); } ?>
you want action take place when user clicks something. let's have table of values , want further information value. html might this:
<table width=100% cellpadding=0 cellspacing=0> <tr> <td width=30% valign=top><span onclick="alert('value 1 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 clicked');">1</span></td> <td width=70% valign=top>description of value 2</td> </tr> </table>
what happen here javascript alert() function called when click on either of 2 leftmost columns of table.
you pass information own script in:
<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 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 clicked');">1</span></td> <td width=70% valign=top>description of value 2</td> </tr> </table> </div>
the net effect same, message displayed. however, update table dynamically using jquery. there number of tutorials on jquery available online. wind javascript function such as:
<script> function myownalert(value) { $.post("getnewtable.php",'v=' + value, function(data) { $("#mytable").html().trigger("create"); }); } </script>
this result in contents of table being replaced output of getnewtable.php script.
note: not meant prime example of using either html or jquery -- mini-tutorial.
Comments
Post a Comment