Jump to content

Archived

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

matfish

Adding/building A Query

Recommended Posts

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

Share this post


Link to post
Share on other sites
Try using return instead. echo sends the output to the browser, where as return returns the value, rather than echoing.

Share this post


Link to post
Share on other sites
I know this isnt really going to make sense but the code is below:-

functions.php
function 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?




Share this post


Link to post
Share on other sites

×

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.