1

I'm trying to do this: When a user click on the briefinfo div which has rows from mysqli, send the student id to id.php where the php file will then get all data by the student id and echo it out so i can use ajax to put it in my original index.php

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>    
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    //in your Javascript, put
    $(document).ready ( function () {
    $("#briefinfo").click (function(){
    $.ajax({  
        type: 'POST',  
        url: 'id.php', 
        var studentid = "<?php echo $studentid; ?>";
        data: { id: studentid },
        success: function(response) {
                $("#briefinfo").html(response);
            }
    });
    });
    });
        </script>

Please help. This is the id.php

<?php

    // connect to the database
    include('connect-db.php');
    // confirm that the 'id' variable has been set
    require_once("db.php");
        $id = $_POST['id'];
        if ($result = $mysqli->query("SELECT * FROM requests WHERE student_id=$id"))
        {
                if ($result->num_rows > 0)
                {
                    echo "<table border='1' cellpadding='10'>";
                    echo "<tr><th>Document #</th><th>Student #</th>
                    <th>Documents needed</th><th>Edit</th><th>Delete</th>
                    <th>recorded comment</th><th>unverify</th><th>comment</th><th>payment amount</th><th>set payment</th>
                    </tr>";


                        while ($row = $result->fetch_object())
                        {
                            echo "<tr>";
                            echo "<td>" . $row->id . "</td>";
                            $studentid=$row->student_id;
                            echo "<td><a href='id.php?id=" . $row->student_id . "'>$studentid</a></td>";
                            echo "<td>" . $row->document . "</td>";
                            echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
                            echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
                            echo "<td>" . $row->comment . "</td>";
                            echo "<td><a href='unverify.php?id=" . $row->id . "'>unverify</a></td>";
                            echo "<td><a href='comments.php?id=" . $row->id . "'>comment</a></td>";
                            echo "<td>" . $row->paymentamount . " pesos";"</td>";
                            echo "<td><a href='paymentamount.php?id=" . $row->id . "'>set amount</a></td>";
                            echo "</tr>";
                        }
                        echo"<br><br>";
                        echo "</table>";
                }
                else
                {
                    echo "No results to display!";
                }
        }
        else
        {
                echo "Error: " . $mysqli->error;
        }

    ?>
2
  • What is "content" related to? Generally this would be something like jQuery('yourdiv').html(response); Commented Mar 1, 2015 at 18:40
  • this is basically a profile thing. so in the #briefinfo, it has student id, name, etc from mysql. I want it to show more data (every row in mysql table) when its clicked. Commented Mar 1, 2015 at 18:43

1 Answer 1

1

Actually... the var was inside the ajax, just add it as the value in the data.

    $.ajax({
    type: 'POST',
    url: 'id.php',
    data: {
        id: "<?php echo $studentid; ?>"
    },
    success: function(response) {
        $("#briefinfo").html(response);
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

I am just guessing because you aren't showing the actual HTML that you want the ajax response added to.
look above. i changed it and still doesn't work. i have no clue why it doesnt work. please help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.