Jump to content

creating a string from an array


_giles_

Recommended Posts

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

 

// 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");		

Link to comment
https://forums.phpfreaks.com/topic/42328-creating-a-string-from-an-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.