Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Unique Arrays removing Duplicates
Old 07-04-2005, 01:00 AM Unique Arrays removing Duplicates
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Hey there,

Unique Arrays

In my database I have
Wood
Delta
Delta

Wood
Delta
Wood
Fire

I would like to be able to do a print out and receive only
Wood
Delta
Fire

My PHP code currently stands as this,

PHP Code:
  function getCompanies() {
   
$sql_text "SELECT * FROM ".$this->TABLES['statements']." ";

    
$data $this->sql->Select($sql_text);
    
$i=0;
    
$n=1;
    
$len count($data);

 for (
$i=0$i$len$i++) {
    
          
$str .=''.$data[$i]['companyname'].'<br>';

}
    return 
$str;
  } 
Which prints out
Wood
Delta
Delta

Wood
Delta
Wood
Fire

I was told array_unique would solve my problems. But I'm not too sure on how to apply it within the code.
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-04-2005, 01:43 AM
rungss's Avatar
Skilled Talker

Posts: 67
Name: Bijay Rungta
Location: Mumbai, India
Trades: 0
Example array_unique() example

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>


The above example will output:

Array
(
[a] => green
[0] => red
[1] => blue
)
rungss is offline
Reply With Quote
View Public Profile Visit rungss's homepage!
 
Old 07-04-2005, 04:23 AM
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Yes, I've seen and tried that example before posting.
Tried to intergrate it, but can't get it working.

Because of the loop i think?
I'm not sure how to add database information pulled into the array and to store it without overwriting it. Each one will need to be unique.
I'm not too hot on the loops.
__________________
Websites Created;
warscope.com
ratepayers.org.nz

Last edited by lothop; 07-04-2005 at 04:41 AM..
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Unique Arrays removing Duplicates
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.02175 seconds with 12 queries