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.

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!");
        });
    });

});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.