I’ve made up a PHP script which assigns a score to listings on a website and assigns it to the results page. I have got it to work in that it shows the score and the details but it keeps listing the same results over and over.
I can’t work out what it is doing but there is a small section of code I was hoping would prevent duplicate listings. Could anyone give it a tweak and see if I am going wring somewhere?
The Code is:
$dupCatch .= $adId.",";
$dupResults = explode(',', $dupCatch);
foreach($dupResults as $dupResult){
if($dupResult == $adId){
print "";
} else {
print $showResults;
$scoreBox = 'THIS IS THE SCORE: ' . $finalScore . '';
print $scoreBox;
}
}
Thanks in advance!
Jack
The problem is that you add your current
$adIdto the duplicate list before you check if it is there – which it will always be, of course.Storing a bunch of numbers in a string,
explodeing it every time, is a little weird, use an array instead. You also don’t need to manually loop through all the items, just usein_array()Needless to say: it would be a better idea to fix the part that gives you the duplicate results in the first place.