Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
1.7k views
in Q2A Core by
Hello,

I want to build this feature and have added in a special div each day another question of my choice.

The questions are allready in the system, now how do I access lets say question number 470 ?

How would I have to change this code, to load only question 470 ?

'<A HREF="'.$question['url'].'">'.$question['title'].'</A>'

Or is it much more complicated ?

Thanks so far

Monk333

1 Answer

0 votes
by
Try this:

$rawquestion=qa_db_single_select($qa_db,
    qa_db_full_post_selectspec(
        qa_get_logged_in_userid($qa_db),
        470
    )
);

You can then access the fields you want from $rawquestion, which will be raw information from the database, not already formatted for HTML. Use print_r() to get an idea of all the fields it contains.

You can get the title to display from qa_html($rawquestion['title']) and the URL from qa_path_html(qa_q_request($rawquestion['postid'], $rawquestion['title'])) - look in function qa_post_html_fields(...) in qa-app-format.php for other ways to convert raw Q info into HTML.
by
Great, thank You so much. Will try it out with the goal to set a variable for the questionsnumber through the admin area or in an external txt file.

Regards
monk333
by
edited by
Works perfectly, once completely ready I will post it here for other interested people.

But now I need to import the Questionnumber 470 for example as a variable.

I made through admin a new page called daily with no link set.

In this page I have added in html only the number 470 in this example.

Now, is there an easy way to read this out and add it to my theme.php as variable ?

I understand that this single html-chapter is saved somewhere in the database, in an lets say fixed place ? So one just would need to load this, and would have the variable with the question number ? And everything woild be done !?

Some hints would help.

The advantage of using the daily page is, that I can set a new daily question from everywhere without accesing my server.

Other suggestions are as well very welcome ! Thank You monk333
by
I found something regarding the database:

qa_pregpages--> VALUES (4, 'daily', '_', 1, 0, 'daily', '', '470');

There the number of the daily page (470 here) is stored.

I as well found the function to get the content of the pages:

qa_db_page_full_selectspec($slugorpageid, $ispageid)

But I cant write the function to get the questionnumber into a variable.

Shouldnt be so complicated, but i am still a beginner. Someone ? Thank You so much.
by
Your best option is to store the question number in the qa_options table.

First choose a name for the option like 'daily_question_id'.

Then add this to the $showoptions array in one of the 'case's near the top qa-page-admin.php, depending on which page you want it to show on.

You can then get the value of this option from within the theme code using qa_get_option($qa_db, 'daily_question_id') - pass that instead of 470.
...