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