Jump to content

Adding/building A Query


matfish

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

Link to comment
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?




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.