matfish Posted June 29, 2006 Share Posted June 29, 2006 Tis difficult to explain, but Ill give it a go:-Iv got a table "Questions" and a table "Answers". Iv done it in functions which will go through the questions and answers and hits the end when reaching 'nxt_group=0' which is the final answer. Within the Answers table there is a "query" column where I want to build a query. So when an answer is clicked it will add "AND answer=whatever" to the query.I cant seem to add the query's up, it just keeps echoing the one Im pressing:-[code]function addToQuery ($query){ global $db_query; $db_query = $db_query.$query; echo $db_query; }[/code]Is it because its in two functions thats looping around that its not adding the string (the query bit of the answers table) as its just displaying the one pressed?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/13190-addingbuilding-a-query/ Share on other sites More sharing options...
wildteen88 Posted June 29, 2006 Share Posted June 29, 2006 Try using return instead. echo sends the output to the browser, where as return returns the value, rather than echoing. Quote Link to comment https://forums.phpfreaks.com/topic/13190-addingbuilding-a-query/#findComment-50765 Share on other sites More sharing options...
matfish Posted June 29, 2006 Author Share Posted June 29, 2006 I know this isnt really going to make sense but the code is below:-functions.phpfunction get1stquestion($nxtgroup)[code]{$folder_list = getAllIDArrayWhere("questionID", "questions", "question_group = $nxtgroup"); if (is_array($folder_list)) { ?> <a name="top"> </a> <p><strong>Is your machine:</strong></p> <ul> <? while ($link_element = each ($folder_list)) { $folder = getRow("questions","questionID", $link_element[1]); $folder2 = getRow("answers","answerID", $link_element[1]); ?> <li><a href="qanda.php?answer=<?=$folder2['answerID']?>&nxt_group=<?=$folder2['nxt_group']?>&query=<?=$folder2['query']?>"><?=$folder['question']?> </a> <?=$folder2['query']?> <? } echo '</ul>'; }}function addToQuery ($query){ global $db_query; $db_query = $db_query.$query; echo $db_query;}function get1stanswer($id ,$nxtgroup){ if ($nxtgroup == 0) { $folder_list = getAllIDArrayWhere("questionID", "questions", "questionID = $id"); } else { $folder_list = getAllIDArrayWhere("questionID", "questions", "question_group = $nxtgroup"); $query_detail = getQuery($id); addToQuery($query_detail); } if (is_array($folder_list)) { ?> <a name="top"> </a> <p><strong>Is your machine:</strong></p> <ul> <? while ($link_element = each ($folder_list)) { $folder = getRow("questions","questionID", $link_element[1]); $folder2 = getRow("answers","answerID", $link_element[1]); ?> <li> <? if ($nxtgroup == 0) { ?> Query: <?=$folder2['query']?> <?=$folder2['answer']?> <br /> <? } else { ?> <a href="qanda.php?answer=<?=$folder2['answerID']?>&nxt_group=<?=$folder2['nxt_group']?>&query=<?=$folder2['query']?>"><?=$folder['question']?> </a> <?=$folder2['query']?> <? } } echo '</ul>'; }}function getQuery($id){ return getBite("query", "answers", "questionID", $id);}[/code]mainpage.php which is initially called first:[code]<?global $db_query;if (isset($_GET['answer'])){get1stanswer($_GET['answer'], $_GET['nxt_group']);}else{ get1stquestion("2");}?>[/code]Even returning it doesnt work. I think its because its stuck in a loop? Even if I could add the values to the GET to pass on it would be good. Just need to try and build the query until it reaches nxt_group=0. Therefore it was in a fuctional loop thingy incase there are loads of questions and answers? Quote Link to comment https://forums.phpfreaks.com/topic/13190-addingbuilding-a-query/#findComment-50768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.