I have a DIV #Message_PHPVARABLE that ought to appear at the bottom of a post when a radio button assigned to this post is selected. What happens however, is that it works fine for Post_1 but when I select an option for Post_2, the option for Post_1 is changed and Message_1 displays the new selection instead of having the Post_2 selection appear in Message_2… any help? The option the radio buttons give is Like and Dislike.
$data = mysql_query("SELECT * FROM Test");
$counter = 1;
while($row = mysql_fetch_array( $data )){
?>
<script type="text/javascript">
$(document).ready(function() {
$("input[name*='like_<?php $counter; ?>']").click(function() {
var defaultValue = $("label[for*='" + this.id + "']").html();
var defaultm = "You have chosen : ";
$('#Message_<?php $counter; ?>').html('').html(defaultm + defaultValue + ' | Value is : ' + $(this).val());
});
});
</script>
<div id="post_<?php $counter; ?>" class="post">
<b><?php echo $row['Title']; ?></b><br>
Expires: <?php echo $row['Exp']; ?><br>
<ul id="listM"></ul>
<div class="left"><p><input id="like_<?php $counter; ?>" type="radio" name="like_<?php $counter; ?>" value="1" />
<label for="like_<?php $counter; ?>">Like</label></p></div>
<div class="right"><p><input id="dislike_<?php $counter; ?>" type="radio" name="like_<?php $counter; ?>" value="0" />
<label for="dislike_<?php $counter; ?>">Dislike</label></p></div>
<hr />
</div>
<div id="Message_<?php $counter; ?>"></div>
<?php
$counter += 1;
}
?>
If I hard code everything (removing the $counter) then it works fine but obviously, with an infinite number of potential rows in the MySQL to be displayed, I must use variables…
You have a problem with your PHP (unless you typed your post incorrectly)
In order to print out
$counteryou need toechoit. Just typing<?php $counter; ?>will not put the value into your HTML. You need to use<?php echo $counter;?>or<?=$counter;?>as a shortcut.