Jump to content


Photo

Adding/building A Query


  • Please log in to reply
2 replies to this topic

#1 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 29 June 2006 - 10:41 AM

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:-


function addToQuery ($query){

    global $db_query;
    $db_query = $db_query.$query;
    echo $db_query;    
}


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



#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 June 2006 - 10:50 AM

Try using return instead. echo sends the output to the browser, where as return returns the value, rather than echoing.

#3 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 29 June 2006 - 11:06 AM

I know this isnt really going to make sense but the code is below:-

functions.php
function get1stquestion($nxtgroup)
{

$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);
}

mainpage.php which is initially called first:

<?

global $db_query;

if (isset($_GET['answer']))
{

get1stanswer($_GET['answer'], $_GET['nxt_group']);

}
else
{

        get1stquestion("2");

}


?>

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?









0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users