Add links to CSV

Reply

Join Date: Dec 2008
Posts: 2
Reputation: IceKnuckle45 is an unknown quantity at this point 
Solved Threads: 0
IceKnuckle45's Avatar
IceKnuckle45 IceKnuckle45 is offline Offline
Newbie Poster

Add links to CSV

 
0
  #1
Dec 28th, 2008
I'm displaying a list of tags on my site which are formatted as CSV for every post.

Example: RFID, robots, decluttering

The CSV tags are stored in the MySQL database as one long string. I would like to make each tag a link that goes to the search page.

Example: search.php?tag=RFID or
search.php?tag=robots

I've found that I can explode the CSV to split it up, then print out the list which basically gives me what I started with. What I'm having problems with is formatting the array to add the links. Also, I would like to get rid of the array formatting [0]=> and place the commas back in between the tags.

My code looks like this:

  1. <?php print_r(explode(',',$string)); ?>

This is my first post, so if you need more info just ask. If there is a better way to proceed please tell.

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: IceKnuckle45 is an unknown quantity at this point 
Solved Threads: 0
IceKnuckle45's Avatar
IceKnuckle45 IceKnuckle45 is offline Offline
Newbie Poster

Re: Add links to CSV

 
0
  #2
Dec 30th, 2008
While browsing the implode manual on php.net I modified the following function.

http://us2.php.net/manual/en/function.implode.php#83464

  1. <?php
  2. function myImplode($before, $after, $glue, $array){
  3. $nbItem = count($array);
  4. $i = 1;
  5. foreach($array as $item){
  6. if($i < $nbItem){
  7. $output .= "$before$item$after$glue";
  8. }else $output .= "$before$item$after";
  9. $i++;
  10. }
  11. return $output;
  12. }
  13.  
  14. $an_array = explode(', ',$stringofCSV);
  15. print myImplode("<a href=\"search.php?tag=\">","</a>",", ", $an_array);
  16. ?>

So basically I exploded my CSV so I could implode them into links. Now I'm stuck on the link portion. I would like the search variable to equal the array item so the link will be: search.php?tag=$arrayItem

Any help would be appreciated. Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC