Page 1 of 1

query results in one string

Posted: Wed Nov 06, 2002 5:36 am
by mixmuis
can i get the query result in 1 string ?

Code: Select all

$result = mysql_query("SELECT * FROM frame77"); 
for($i=0;$i < mysql_numrows($result);$i++){ 

$mod = "<a href='article.php?". mysql_result($result,$i,'name')."'>itemname</a><br>";

}

echo"$mod";
the $mod must be used in a other file, so i would like to use it as 1 string.

someone who can help me?

Posted: Wed Nov 06, 2002 7:29 am
by f1nutter
You could add each iteration to an array by changing

Code: Select all

$mod = "<a href='article.php?". mysql_result($result,$i,'name')."'>itemname</a><br>";
to

Code: Select all

$modї] = "<a href='article.php?". mysql_result($result,$i,'name')."'>itemname</a><br>";
(note square brackets)

Then

Code: Select all

$string = implode(" ", $mod);
to convert the array into a string, with each element seperated by a space. Then pass the string.

You could probably be more efficient by using SELECT name FROM frame77 instead of selecting everything. I suspect there is also a better way of looping, I prefer a different way, but if this is what you like, only change a little at a time or suddenly it won't work an you won't know why!