php - Multiple star rating forms in a single page

one text

I have a home.php page in which I load posts with an Ajax function from load_posts.php This is the important code of load_posts.php:

...
$userid = $_POST['userid'];
$sql = mysqli_query($conn, "SELECT * FROM storie WHERE userid IN (SELECT following FROM follow WHERE follower='$userid')");
while($row = mysqli_fetch_assoc($sql)){
$idsto=$row['storia_id'];
...
?>
<div class="storia" id="storia_<?php echo $idsto;?>">
...
<div class="star-rating">
      <input id="star-5" type="radio" name="rating" value="5" class="stellette" />
      <label for="star-5" title="5 stars">
        <i class="active fa fa-star fa-sm" aria-hidden="true"></i>
      </label>
      <input id="star-4" type="radio" name="rating" value="4" class="stellette"/>
      <label for="star-4" title="4 stars">
        <i class="active fa fa-star fa-sm" aria-hidden="true"></i>
      </label>
      <input id="star-3" type="radio" name="rating" value="3" class="stellette"/>
      <label for="star-3" title="3 stars">
        <i class="active fa fa-star fa-sm" aria-hidden="true"></i>
      </label>
      <input id="star-2" type="radio" name="rating" value="2" class="stellette"/>
      <label for="star-2" title="2 stars">
        <i class="active fa fa-star fa-sm" aria-hidden="true"></i>
      </label>
      <input id="star-1" type="radio" name="rating" value="1" class="stellette"/>
      <label for="star-1" title="1 star">
        <i class="active fa fa-star fa-sm" aria-hidden="true"></i>
      </label>
    </div>
</div>
<?php
}
?>

I'd like to have two jQuery variables, one with the value of the $idsto rating, and the other with the rating checked value from 1 to 5.

When I have only one single rating in a page, I simply do this:

$('input[name=rating]').change(function(){
var voto = $( 'input[name=rating]:checked' ).val();

But now I don't know how to get the specific rating of the id $idsto. I tried writing this, but with no results:

$("input[name^='rating']").change(function(){
...
name="rating_<?php echo $idsto;?>"

Can anyone help me?

Source