Hi,

I've created a function which checks to see if a 'id' for a station exists in the users list of saved stations which are stored as comma seperated.

The issue I'm having is that the foreach doesn't seem to be looping past the first value and thus it is saving the station id to the users list even though he already has that station saved.

Any tips or pointers?

Thanks

PHP Code:
function updateStationList($user$station) {
        
$col '';
        
$db db::getInstance();
        if (
$result $db->query("SELECT `user_saved_stations` FROM `users` WHERE user_id = "intval($user))) {
            if (
$row $db->getrow($result)) {
                
//check user has any stations
                
if($row['user_saved_stations']=='') {
                    
//add new station
                    
$col.= "SET `user_saved_stations` ='"intval($station)."'";
                    
$sql "UPDATE `users` "$col ." WHERE `user_id`='".$user."'";
                    if (
$result $db->query($sql)) {
                        return 
true;
                    }
                } else if (
$row['user_saved_stations']!='') {
                    
                    
//check this station isn't already registered to the user.
                    
$list explode(",",substr($row['user_saved_stations'],0));
                    
print_r($list);
                        foreach(
$list as $item) {
                            if(
$result $db->query("SELECT * FROM `users` WHERE $item IN ($station) AND user_id = $user")) {
                                echo 
"SELECT * FROM `users` WHERE $item IN ($station) AND user_id = $user";
                                if (
$db->getrow($result)) {
                                    
//do nothing/
                                    
return true;
                                
                                } else {
                                    
$col.= "SET `user_saved_stations` ='"$row['user_saved_stations'].",".intval($station)."'";
                                    
$sql "UPDATE `users` "$col ." WHERE `user_id`='".$user."'";
                                    if (
$result $db->query($sql)) {
                                        return 
true;
                                    }
                                }
                            } 
                        }
                
                    }
                }
        }
        return 
false;    
        
    }