Page 1 of 1

creating a string from an array

Posted: Mon Mar 12, 2007 3:56 am
by giles
Hi,

I want to concatenate a number of db entries into a single string (forming a summery) I’ve come up with something that illustrates the principle, I can see that I need some sort of loop that reads each array element into the string, and then exits the loop - however my lack of experience has now got the better of me. Can you help?
- thanks in advance
- Giles

Code: Select all

// db query
$Ddb2_query = mysql_query 
(
	"SELECT 
		answer 
	FROM ddb 
	WHERE session_id = '$session_id' 
	AND cache = '$cacheRecall' "
);

if (!$Ddb2_query) 
{
	echo 'Could not run query - page.inc Ln 335 - ' . mysql_error();
	exit;
}
				
// read query results into temp array		
for($i=0; $row2 = mysql_fetch_array($Ddb2_query); $i++)
{
	global $tempAnswer;
	$tempAnswer[$i] = answerDecode($row2["answer"]);
}
				
// prepare to return above into a form using pear’s HTML_template_IT
// ANSWER is the field that will hold the result
// the concatenated $tempAnswer is where the sting should go
$template->setCurrentBlock("answer");
$template->setVariable
	(
	"ANSWER", 
		(
			$tempAnswer[0] . "<br><br>" .
			$tempAnswer[1] . "<br><br>" .
			$tempAnswer[2] . "<br><br>" .
			$tempAnswer[4] . "<br><br>" .
			$tempAnswer[5] . "<br><br>" .
			$tempAnswer[6]
		)
	);
$template->parseCurrentBlock("answer");

Posted: Mon Mar 12, 2007 4:01 am
by mikeq

Code: Select all

$TheAnswer = implode("<br /><br />",$tempAnswer);
implode()

Posted: Mon Mar 12, 2007 1:04 pm
by giles
Hey mikeq,

Your signature made me smile,
I guess by default my posting removed any doubt,
but I’m pleased I did it,
and I’m in your deby for your response,
thank you
it makes all the difference! :D

Posted: Mon Mar 12, 2007 7:32 pm
by mikeq
Hi,

My signature applies more to me than anyone else. After I post any reply I always see my signature and think "Have I?"

No such thing as a stupid question, you either know the answer or not.