Jump to content

Passing a value in MySQL query using jQuery


Recommended Posts


Id  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


    include ‘db_connection.php’;
    $sql = "SELECT * FROM users";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
    <td><?php echo $row[userID]?></td>
        <div id='basic-modal'>
            <a href="?id=<?php echo $row[userID]?>"  class='basic'>Show</a>

<?php } ?>


This is the link 

<div id='basic-modal'>
<a href="?id=<?php echo $row[userID]?>"  data-mydata="<?php echo $row[userID]?>" 

and this is the script which retrieves data.

jQuery(function ($) {
    $('#basic-modal .basic').click(function (e) {
            return false;


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); 

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.





Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.