0

I have this code example

<?php $sel_query = "SELECT * FROM tbl_name ORDER BY id DESC";
$res_query = mysql_query($sel_query);
while($arr_my_array = mysql_fetch_array($res_Query)){
    $cl_id = $arr_my_array['client_id'];
    ?>

    <input type="hidden" id="hdn<?php echo $cl_id ?>" name="hdn<?php echo $cl_id ?>" value="<?php echo $cl_id ?>" />
    <input type="button" id="btnget<?php echo $cl_id ?>" name="btnget<?php echo $cl_id ?>" value=">>" />
<?php    
}
?>

I have a jquery that gets the value of the $cl_id and I only get the first id, the next records does not display their corresponding ids. do you have any suggestion that will get the value of the id withing that while loop?
so that from there once I get the id I can capture that value and use that for another query.

Pardon for the code its really ancient.

Thanks in Advance.

2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by AleMonteiro
0

I'd suggest you wrap the input hidden and the button in a <div> or <span>, that has an specific class(in this case I set as cl_id).
The result should look something like:

<div class="cl_id">
    <input type="hidden" id="hdn<?php echo $cl_id ?>" name="hdn<?php echo $cl_id ?>" value="<?php echo $cl_id ?>" />
    <input type="button" id="btnget<?php echo $cl_id ?>" name="btnget<?php echo $cl_id ?>" value=">>" />
</div>

Then you can loop all your inputs like this:

$(function() { // Onload

    $("div.cl_id").each(function() { // for each div

        var $this = $(this), // the <div>
            $input = $this.children("input:text"), // the input hidden
            $btn = $this.children("input:button"), // the input button
            cl_id = $input.attr("id").replace("hdn", ""); // the cl_id 

        // If you want to add an click listener to your button, you could do it like this:
        $btn.click(function() {
            alert("Button with cl_id " + cl_id + " clicked!");
        });
    });

});
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.