Page 1 of 1

Show all data in one string ?

Posted: Fri Oct 27, 2006 3:49 am
by Dale
I currently have my code (php) looking at the searches listed in my database which are in a field called SEARCHES (Fields: sid, searchterm), now i'm trying to get all the searchterms to be available as one tag.

eg;

(in database)
SID = 1
Searchterm = dale hay

SID = 2
Searchterm = devnetwork

SID = 3
Searchterm = kittens in microwave

Now I'm wondering how I can get it so it reads them all out the database (which I know how to do) however it won't all add as one tag. >=[

Code: Select all

$sql = "SELECT * FROM searches";
$result = mysql_query($sql, $conn) or die(mysql_error());
while($r = mysql_fetch_array($result)) {
	$thewords = $r['searchterm'];
}
^ Thats what i'm got so far, and before I used:

Code: Select all

$thewords = "dale hay devnetwork kittens in microwave";
but I want to scrap the manual way of doing it and have it being generated in teh database. Any ideas?

(Soz if that seems longwinded and boring and effortless... :/)

Posted: Fri Oct 27, 2006 4:16 am
by volka
try

Code: Select all

$sql = "SELECT * FROM searches";
$result = mysql_query($sql, $conn) or die(mysql_error());
$thewords = '';
while($r = mysql_fetch_array($result)) {
	$thewords .= $r['searchterm'] . ' '; // note the dot in .=
}