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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.