question about INSERT / queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JoeFritz
Forum Newbie
Posts: 2
Joined: Fri Dec 05, 2003 9:04 pm

question about INSERT / queries

Post by JoeFritz »

does anyone know how friendster does the thing where you can enter a string of words into a form where you are supposed to type, for example, "favorite bands:". so you type in your favorite bands, seperated by commas and submit the form. when it displays your page of favorite bands, it takes the band names and makes each one into a link that takes you to a page that lists everyone with that band in their favorites.

i don't know how vague i am being, but if you need more of an explanation i could try. basically i'd just like to know how you can take a string of words seperated by commas and make them each into individual variables.

any suggestions? thanks...
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

check out the example of explode() on the manual page
http://us4.php.net/manual/en/function.explode.php
insert the values of the resulting array into your database..

Code: Select all

"INSERT INTO favorites (fav1,fav2,fav3) VALUES ('{$favsї0]}','{$favsї1]}','{$favsї2]}')"
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Code: Select all

$somestring = "britney,bsb,nsync";
$bands = explode(",", $somestring);

for ($i = 0; $i < count($bands); $i++) {
     echo "<a href="somepage.php?band=".$bands[$i]."">".$bands[$i]."</a>";
}
Something like that.
titan
Forum Newbie
Posts: 1
Joined: Sun Jul 03, 2005 8:24 pm

Post by titan »

that's really cool, microthick! i try your code and get this:

britney, bsb, nsync,

with a link in each word.. but the question is "how to remove last comma after nsync or how to make the result like this below?"

britney, bsb, nsync

thx a lot for your time
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Post Reply