Page 1 of 1

question about INSERT / queries

Posted: Sat Jan 03, 2004 9:11 pm
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...

Posted: Sat Jan 03, 2004 9:38 pm
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]}')"

Posted: Sat Jan 03, 2004 9:49 pm
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.

Posted: Sun Jul 03, 2005 8:34 pm
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

Posted: Mon Jul 04, 2005 7:49 am
by timvw