Ich habe einen Aufruf zu einer Autoload-Funktion in meiner index.php-Datei, um mehr Daten zu laden, wenn Sie den unteren Rand der Seite erreichen. Ich sehe auch hier den Stil für meine Bewertung (Sterne):Autoloading neue Bewertung/Start Systemdaten in einer Website, wenn Sie zum Ende der Seite
<style>
span.stars, span.stars span {
display: block;
background: url(stars.png) 0 -16px repeat-x;
width: 80px;
height: 16px;
}
span.stars span {
background-position: 0 0;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
var track_load = 0; //total loaded record group(s)
var cityname = '<?=$city;?>';
var loading = false; //to prevents multipal ajax loads
var total_groups = <?=$total_groups;?>; //total record group(s)
var total_rows = <?=$get_total_rows;?>;
$('#results').load("autoload_process.php", {'group_no':track_load,'nameofcity':cityname}, function() {track_load++;}); //load first group
$(window).scroll(function() { //detect page scroll
if($(window).scrollTop() + $(window).height() == $(document).height()) //user scrolled to bottom of the page?
{
if(track_load <= total_groups && loading==false) //there's more data to load
{
loading = true; //prevent further ajax loading
$('.animation_image').show(); //show loading image
//load data from the server using a HTTP POST request
$.post('autoload_process.php',{'group_no': track_load, 'nameofcity':cityname}, function(data){
$("#results").append(data); //append received data into the element
//hide loading image
$('.animation_image').hide(); //hide loading image once data is received
track_load++; //loaded group increment
loading = false;
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
$('.animation_image').hide(); //hide loading image
loading = false;
});
}
}
});
});
</script>
Da ist in meinem autoload_process.php ich Informationen aus meiner Datenbank abrufen und ich drucken. Eine der Informationen, die ich abrufen und drucken, ist die Bewertung. Ich habe auch in dieser Datei mein Skript, um die Bewertung zu drucken.
<script type="text/javascript">
$(function() {
$('span.stars').stars();
});
$.fn.stars = function() {
return $(this).each(function() {
$(this).html($('<span />').width(Math.max(0, (Math.min(5, parseFloat($(this).html())))) * 16));
});
}
</script>
$db = pg_connect("$db_host $db_name $db_username $db_password");
$query = "SELECT * FROM table;
$rating = $myrow[rating];
echo '<span class="stars">';
echo $rating;
echo '</span>';
Wenn die Seite Last zum ersten Mal alles funktioniert gut, aber das Problem ist, dass ich, wenn ich auf den Boden der ganzen Weg bewegen und die Seite mit den neuen Informationen der Rating-Änderungen neu geladen wird. Es scheint, dass jedes Mal, dass ein neuer Satz von Daten alle bisherigen Bewertungen auf den Wert festgelegt des ersten Elements aller (Hotel 1 gemäß Beispiel)
Beispiel geladen wird: (lassen Sie uns sagen, dass ich laden 3 Ergebnisse zur gleichen Zeit)
Ersten Last:
Hotel 1 --> Rating 5 (This is correct)
Hotel 2 --> Rating 4 (This is correct)
Hotel 3 --> Rating 3 (This is correct)
Jetzt komme ich zum Ende der Seite und die nächsten Info geladen (zweite Last):
Hotel 1 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 2 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 3 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 4 --> Rating 2 (This is correct)
Hotel 5 --> Rating 1 (This is correct)
Hotel 6 --> Rating 3 (This is correct)
Jetzt komme ich zum Ende der Seite und die nächsten Info geladen wird (dritte Last):
Hotel 1 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 2 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 3 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 4 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 5 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 6 --> Rating 5 (This is INCORRECT) filled with first value (Hotel1)
Hotel 7 --> Rating 3 (This is correct)
Hotel 8 --> Rating 2 (This is correct)
Hotel 9 --> Rating 1 (This is correct)
Jede Hilfe
Vielen Dank Thomas für Ihre Antwort. Ich habe nur diese Abfrage als Beispiel in meinem Code Ich habe "ORDER BY Bewertung DESC LIMIT $ items_per_group OFFSET $ Position" ". Das Problem ist mit der