0

i have a column of user names and every name is repeating one or more than one. i want to display that user name maximum one time through php or sql query. Any suggestions please?

  • 1
    Sounds like you need something like a regular expression. http://us2.php.net/preg_match Could you give an example of what you're trying to do? – azelma Apr 07 '14 at 23:39
  • This helped me out: http://webcheatsheet.com/php/regular_expressions.php – Jack Apr 07 '14 at 23:41
  • Take a look at this String comparison using == vs. strcmp http://stackoverflow.com/questions/3333353/string-comparison-using-vs-strcmp – dpineda Apr 07 '14 at 23:41
  • i am just getting character from my text feild and there is function substr() which matches my input to first character of already stored string and then it returns the whole string but i want that if my input is matched to any character in the string then is should return the whole string –  Apr 07 '14 at 23:44

1 Answers1

1

I think i understand your problem you want to get rid of the repeating elements from your result returned by sql so if you are working in php you can do it by:

1) get your result in ascending order

2) do this in your php code

     $temp=NULL;
     $names=array();
     $i=0;
foreach($result as $row){ 


   if($row->id!=$temp){
       $temp=$row->id;

       $name[$i]=$temp;
       $i++;
      }
                          }
Datta
  • 150
  • 1
  • 1
  • 9