_giles_ Posted March 12, 2007 Share Posted March 12, 2007 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 More sharing options...
trq Posted March 12, 2007 Share Posted March 12, 2007 $template->setVariable("ANSWER",implode("<br /><br />",$tempAnswer)); Link to comment https://forums.phpfreaks.com/topic/42328-creating-a-string-from-an-array/#findComment-205332 Share on other sites More sharing options...
_giles_ Posted March 12, 2007 Author Share Posted March 12, 2007 hey thorpe works a treat, thank you for your response. REALLY makes a difference to this newbie to have the likes of you guy's around to help out - thanks again. Giles Link to comment https://forums.phpfreaks.com/topic/42328-creating-a-string-from-an-array/#findComment-205598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.