I am trying to pass variables to jquery for ajax from html/php.
This is the html/php:
<?php
$propertyid = $data['property_id'];
$select5 = $con->prepare("SELECT favorite_properties_id, favorite_properties_property_id FROM tbl_favorite_properties where favorite_properties_user_id = '".$_SESSION['user_id']."' AND favorite_properties_property_id='$propertyid;'");
$select5->setFetchMode(PDO::FETCH_ASSOC);
$select5->execute();
while($data5=$select5->fetch()){
echo $data5['favorite_properties_id'];
$favorite_properties_id = $data5['favorite_properties_id'];
}
?>
<a href="#">
<img class="addtofavoritebutton" pid="<?php echo $propertyid; ?>" fpid="<?php echo $favorite_properties_id;?>" src="../images/system/addtofavorite.png">
</a>
<?php echo $data['property_id']; ?>
This is the jquery:
$('.addtofavoritebutton').click(function() {
var property_id = $(this).attr('pid');
var favorite_properties_id = $(this).attr('fpid');
alert(property_id);
alert(favorite_properties_id);
});
There are two rows in the tbl_favorite_properties, table however jquery is picking up the last row for fpid, even when there is no data. When I echo in php then the value is blank (as it should be) but in jquery it is taking the last row and repeating the value, when it can't find. How can I get jquery to pick up the blank or null value just like php?