Closed velhbxtyrj closed 5 years ago
In general it's better "empty($ranking)" or "$ranking == false" to check if an array is empty or not.
So, it should be something like this:
if(empty($ranking)) echo "..."; else if(...) etc.
(I'm not at the PC right now, I can't format the code properly)
Ok, this is the full code:
if(!empty($ranking)){
if($start != 1 && $start + 20 < count($ranking)) {
echo "<a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start - 20)."\">« back</a> | <a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start + 20)."\">forward »</a>";
}
else if($start == 1 && $start + 20 < count($ranking)) {
echo "« back | <a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start + 20)."\">forward »</a>";
}else if($start != 1 && $start - 20 < count($ranking)) {
echo "<a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start - 20)."\">« back</a> | forward »";
}
else echo "« back | forward »";
}
else echo "« back | forward »";
And unless it is not necessary in the second if to remove here this line?
else echo "« back | forward »";
This line is moved to the first if
It could be reduced in a single if, with something like this:
if(empty($ranking) || count($ranking) <= 20){
echo "« back | forward »";
}else if($start != 1 && $start + 20 < count($ranking)) {
echo "<a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start - 20)."\">« back</a> | <a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start + 20)."\">forward »</a>";
}else if($start == 1 && $start + 20 < count($ranking)) {
echo "« back | <a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start + 20)."\">forward »</a>";
}else if($start != 1 && $start - 20 < count($ranking)) {
echo "<a href=\"statistiken.php?id=".$_GET['id']."&rank=".($start - 20)."\">« back</a> | forward »";
}
It will be better if you correct this warning yourself :)
It turned out that it was a bigger problem than I expected, caused by calling with the same name 2 variables in the same scope ($ranking).
This warning is displayed if there are no players in the statistics at all.
If this is the right decision then can implement it:
The selected part is bold:
else if($start == 1 && $start+20 < count($ranking)) {
Replace with the selected part in bold
else if($start == 1 && $start+20 < count([$ranking])) {