I have some loop using data from SQlite db and then i show all that data using bootstrap ul/li and data from database.
Code is something like this (without opening and closing php tags):
$results = $db->query("SELECT * FROM igre WHERE cat = 'slot'");
<div class="container-fluid">
<div class="row">
while($row=$results->fetchArray(SQLITE3_ASSOC)){
$game= $row['kod'];
<div class="gallery_product col-xs-6 col-sm-4 col-md-2 col-lg-2">
<span onclick="spremi()">
<i class="fas fa-star fav-icon"></i></span><a href="#" class="tranzicija zacrni"><img src="sample.jpeg"></a>
</div>
}
</div>
</div>
I defined variable like $game= $row['kod']; and i it works fine in this loop, but the problem is when i try to use this variable value in jquery function that i use for storing data.
The function i use for storing data onclick (spremi) only get's value from last record, not from record i clicked on:
<script>
function spremi(){
$korisnik = "<?php echo $uid;?>";
$kod = "<?php echo $game;?>";
$.ajax({
url: "prihvati.php",
data: {korisnik : $korisnik, igra : $kod},
type: "GET",
dataType: "json",
//on success
success: function(data){
},
error: function(){
}
});
}
I need this function to work fine for every record, for example if the game is "ABC" to read that from $game variable, or second game is "TRZ" to save that, and so on...