web_garaux Posted May 7, 2014 Share Posted May 7, 2014 Hello, I’d have a question to ask. First, let me explain what I want to achieve. In a table I display several links whose value (user id) is extracted from a database. By clicking on the link appears a modal pop up in which I would like to pass the selected value in a query using MySQL. Here is the table <table> <tr> <td>Username</td> <td>Id</td> </tr> <?php include ‘db_connection.php’; $sql = "SELECT * FROM users"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ ?> <tr> <td><?php echo $row[userID]?></td> <td> <div id='basic-modal'> <a href="?id=<?php echo $row[userID]?>" class='basic'>Show</a> </div> </td> </tr> <?php } ?> </table> This is the link <div id='basic-modal'> <a href="?id=<?php echo $row[userID]?>" data-mydata="<?php echo $row[userID]?>" class='basic'>Show</a> </div> and this is the script which retrieves data. <script> jQuery(function ($) { $('#basic-modal .basic').click(function (e) { $('#basic-modal-content') .text($(this).data('mydata')) .modal(); return false; }); }); </script> Now I would like to pass the value in a SELECT through a variable named $userId as shown below in order to show the user data. <div id="basic-modal-content> $sql = "SELECT * FROM user WHERE id = $userId"; $res = mysql_query($sql); $row = mysql_fetch_array($res); ?> </div> Since I have little familiarity with the jQuery plugin I would like to ask you how to pass the selected id in the variable named $userId within the SELECT. Thanks Quote Link to comment Share on other sites More sharing options...
gristoi Posted May 7, 2014 Share Posted May 7, 2014 i think you need to read up a little more on your mysql and php. these are server side languages, which means that by the tie your page is rendered all proccesing in the php and mysql has completed. What you 'need' to do is fire off an ajax request to a php script on the backend to process your request Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.