AlenD Posted August 11, 2011 Share Posted August 11, 2011 Hello, I have a div that contains echos from mySQL. I have another div that echos the titles of the contents of the table. I want to change the contents of the div depending on which title I click. I have placed unique IDs for the titles, so I was wondering how I could change the content of the div. Link to comment https://forums.phpfreaks.com/topic/244461-changing-variables-and-reloading-sql-query-with-java-scriptjquery/ Share on other sites More sharing options...
AlenD Posted August 11, 2011 Author Share Posted August 11, 2011 By the way, my code looks like this: Basically I want to change the display of the echos of query 2 when I click query 1. <?php include "backend/settings.php"; mysql_connect ("localhost", $username, $password); <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="scripts/jquery-1.6.2.min.js"></script> <script> $(document).ready(function(){ $("#atdisp").click(function(){ $("").html(?); }); }); </script> </head> <body> <?php $query = "SELECT * FROM activities"; $result = mysql_query($query); $num = mysql_numrows($result); $id = mysql_result($result, 0, "id"); $i = 0; while ($i < $num) { $title = mysql_result($result, $i, "title"); echo '<div id="atdisp" class="atdisp2"><a href="#">'.$title.'</a></div><div class="spacer"></div>'; $i++; } ?> <?php $query2 = "SELECT * FROM activities WHERE id = $id"; $result2 = mysql_query($query2); $title = mysql_result($result2, 0, "title"); $date = mysql_result($result2, 0, "date"); $machinery = mysql_result($result2, 0, "machinery"); $info = mysql_result($result2, 0, "info"); $image = mysql_result($result2, 0, "image"); echo '<div id="cdisp">'; echo '<div id="tdisp">'.$title.'</div><div class="spacer"></div>'; echo '<div id="ddisp">'.$date.'</div><div class="spacer"></div>'; echo '<div id="idisp">'.$info.'</div><div class="spacer"></div>'; $list = explode(",",$machinery); foreach($list as $machinery){ echo '<div id="mdisp"><li>'.$machinery.'</li></div>'; } echo '<div id="pdisp"><img src="images/'.$image.'" /></div>'; echo '</div>'; mysql_close(); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/244461-changing-variables-and-reloading-sql-query-with-java-scriptjquery/#findComment-1255643 Share on other sites More sharing options...
nogray Posted August 11, 2011 Share Posted August 11, 2011 You need to use Ajax. Link to comment https://forums.phpfreaks.com/topic/244461-changing-variables-and-reloading-sql-query-with-java-scriptjquery/#findComment-1255711 Share on other sites More sharing options...
AlenD Posted August 11, 2011 Author Share Posted August 11, 2011 Okay, I am prepared to self study and learn, but please direct me to what part I should be looking into please. Link to comment https://forums.phpfreaks.com/topic/244461-changing-variables-and-reloading-sql-query-with-java-scriptjquery/#findComment-1255795 Share on other sites More sharing options...
nogray Posted August 11, 2011 Share Posted August 11, 2011 Since you are using jQuery, you might want to start at http://api.jquery.com/category/ajax/ (review this part as well http://api.jquery.com/jQuery.get/ for getting data using ajax). Lots of examples to follow Link to comment https://forums.phpfreaks.com/topic/244461-changing-variables-and-reloading-sql-query-with-java-scriptjquery/#findComment-1256058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.