Rodis Posted February 4, 2009 Share Posted February 4, 2009 Hi, I'm struggling with a piece of code i think might not even be possible cause i have serached and searched and i cannot succeed so hope somebody advanced can help me out. i have this database for test en creation of code: id subject tags ------------------------------------------------ 17 cat3 multi en multi 18 cat4 nog een keer dubbel 19 cat5 plus en plus 16 cat2 dubbel dubbel 15 cat1 keer op keer Nou what i am trying to acheive is to get the results i get from de tags field into one array. so i can get a comma between each word and most important remove double entries. i have a piece of code that will do this but not all in one but sepperately so for each id at a time this will still result in double words since they are in diferent fields. So the result i want from this example is: multi,en,nog,een,keer,dubbel,plus,op, what i have achieved already is: multi,en, nog,een,keer,dubbel, plus,en, dubbel, keer,op, I have tried different things already but can't seem to escape the while loop. Either it gets handled differnet arrays or just the latest entrie alone. This is a piece of code i have at the moment. while ($get = $db->Rows()){ // $newarray[] = $get['tags']; $a = $get['tags']; $newarray = "".$a.",\n"; $array1 = array(', ',' '); $array2 = array(',',','); $keywords = str_replace($array1,$array2,$newarray); $explode = explode(',', $keywords); $merge = array_merge($explode); }// end while Can someone help me with this or tell me if it is even possible to do this. Hope i explained so you can understand. i am dutch so appoligies for my bad english. GreetZ. Link to comment https://forums.phpfreaks.com/topic/143765-solved-multiple-field-of-a-column-in-one-array/ Share on other sites More sharing options...
printf Posted February 4, 2009 Share Posted February 4, 2009 Something like... <?php mysql_connect ( 'localhost', 'user', 'pass' ); mysql_select_db ( 'database' ); $result = mysql_query ( "SELECT REPLACE(TRIM(tags), ' ', ',') AS tags FROM table;" ); $out = ''; while ( $row = mysql_fetch_assoc ( $result ) ) { $out .= $row['tags']; } $out = array_keys ( array_flip ( explode ( ',', $out ) ) ); print_r ( $out ); ?> Link to comment https://forums.phpfreaks.com/topic/143765-solved-multiple-field-of-a-column-in-one-array/#findComment-754320 Share on other sites More sharing options...
Rodis Posted February 4, 2009 Author Share Posted February 4, 2009 OMG that helped me alot needed just a litle more code to get the final result i wanted. This was it: $db->select = "SELECT REPLACE (trim(tags),'',',') AS tags FROM t_keywords"; $db->Query(); echo "<p><div class=container >"; // keywords uit resultaten halen en plaatsen in meta tag. $out = ""; while ($get = $db->Rows()){ $out .= "".$get['tags'].","; $array1 = array(', ',' '); $array2 = array(',',','); $keywords = str_replace($array1,$array2,$out); }// end while $out = array_keys ( array_flip ( explode ( ',', $keywords ) ) ); $implode = implode(',',$out); echo($implode); // end keywords uit resultaten halen en plaatsen in meta tag. echo "</div>"; Thanx a lot, There are some things that where new to me and down know why it worked how it worked so thats something for me to look up reaaly learned here. Like in here $out .= "".$get['tags'].","; the point before the = changes everything. Anyways i got what i wanted here no i can finish my site was stuck there for a while :-) Thanks again. Link to comment https://forums.phpfreaks.com/topic/143765-solved-multiple-field-of-a-column-in-one-array/#findComment-754620 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.