I need a better solution then this, I'm using <span id="<?php echo $row['art_id']" name="<?php echo $row['art_featured']"></span> to get the values from fields from my database so I could send them through jQuery Ajax, but there has to be a better way to use the values from my database and storing them in a jQuery VAR then this, any suggestions would be great thanks in advance!
jQuery
$(document).ready(function(){
$(".star").click(function(){
var art_id = $(this).attr('id');
var art_featured = $(this).attr('name');
$.ajax({
type: "POST",
data: {art_id:art_id,art_featured:art_featured},
url: "ajax-feature.php",
success: function(data){
if(data != false) {
}
else {
}
}
});
});
});
PHP
<section class="row">
<?php
$sql_categories = "SELECT art_id, art_featured FROM app_articles";
if($result = query($sql_categories)){
$list = array();
while($data = mysqli_fetch_assoc($result)){
array_push($list, $data);
}
foreach($list as $i => $row){
?>
<div class="row">
<div class="column one">
<span id="<?php echo $row['art_id']; ?>" class="icon-small star"></span>
</div>
</div>
<?php
}
}
else {
echo "FAIL";
}
?>
</section>
So would I be able to use the data-object thing with the ajax data: ?