$sql = "SELECT * FROM 'votes'"; while($row=mysql_fetch_array($sql)){ $id=['id']; if($id>0&&isset($y)){ if($y>$id){ $y=$id; } } else{ $y=0; } }