| | |
Add links to CSV
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
This is my first post, so if you need more info just ask. If there is a better way to proceed please tell.
Thanks.
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:
PHP Syntax (Toggle Plain Text)
<?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.
While browsing the implode manual on php.net I modified the following function.
http://us2.php.net/manual/en/function.implode.php#83464
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.
http://us2.php.net/manual/en/function.implode.php#83464
PHP Syntax (Toggle Plain Text)
<?php function myImplode($before, $after, $glue, $array){ $nbItem = count($array); $i = 1; foreach($array as $item){ if($i < $nbItem){ $output .= "$before$item$after$glue"; }else $output .= "$before$item$after"; $i++; } return $output; } $an_array = explode(', ',$stringofCSV); print myImplode("<a href=\"search.php?tag=\">","</a>",", ", $an_array); ?>
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.
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- Display output to excel (Java)
- Open In New Window Php (PHP)
Other Threads in the PHP Forum
- Previous Thread: multiple images
- Next Thread: How to post form to database and to an url
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file files filter folder form forms forum function functions gc_maxlifetime global google headmethod href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php phpmysql query question random recourse recursion regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube





