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

Hello,

   I have seen users ask this question, but there is no solution posted. I have seen it implemented on the website  (http://www.prepare4interview.com/877/how-would-you-create-a-ssis-package-based-on-below-scenario?qa_theme=p ) There is a Previous and Next buttion. 

 

Looking for same functionality code to have PREVIOUS and NEXT buttons to navigate to next question. It will really enhance the user experience. I am not a PHP guy, appreciate someone to help all of us on this.


Cheers,

 

 

 

Q2A version: 1.5.2

4 Answers

0 votes
by
I'm interested in this code/plugin as well.
0 votes
by
Yes, a very interesting feature !!!
0 votes
by
Okay most of the part is done just need to knwo how to get current question id and done... The code I have writeen has been tested once find solution to get current question id than will post code here.
by
You can use in advanced theme:

if ($this->template=='question') {
                $myurl=$this->request;
                $myurlpieces = explode("/", $myurl);
                $myurl=$myurlpieces[0];
.......

Then $myurl works as id. I have that working but I have too many database accesses...i am interested if Your solution will be faster...
by
Check this meanwhile. I have tried both query but none of giving me current id

http://www.question2answer.org/qa/19372/get-current-post-id

I am working on it so get back to you in few minutes.
by
Okay this is working wonderful. Can you explain bit of code..
by
if ($this->template=='question') { // only doit if on question page
                $myurl=$this->request; // take request everything after www.domain.com/......request.....
                $myurlpieces = explode("/", $myurl); //explode it into an array on each slash / position
                $myurl=$myurlpieces[0]; // take the first piece what in our example is the number like: ..domain.com/NUMBER/...
by
Excellent! I have done code and posted here. Without your help it wouldn't possible. Thanks :)
+2 votes
by
edited by

Okay so here is the final code. I will make plugin with some additional options in few days and upload on github. However anyone want to use this direct code here it is.

Place this entire code into qa-theme.php file

Great thanks to monk333 to help me to get current question id

 

// get previous question
function get_prev_q(){
 
$myurl=$this->request;
$myurlpieces = explode("/", $myurl);
$myurl=$myurlpieces[0];
 
$query_p = "SELECT * 
FROM ^posts 
WHERE postid < $myurl
AND type='Q'
ORDER BY postid DESC
LIMIT 1";
 
$prev_q = qa_db_query_sub($query_p);
 
while($prev_link = qa_db_read_one_assoc($prev_q, true)){
 
$title = $prev_link['title'];
$pid = $prev_link['postid'];
 
echo '
<A HREF="'. qa_q_path_html($pid, $title) .'" title="'. $title .'" >&larr; Prev Question </A>';
}
 
}
 
// get next question
function get_next_q(){
 
$myurl=$this->request;
$myurlpieces = explode("/", $myurl);
$myurl=$myurlpieces[0];
 
 
$query_n = "SELECT * 
FROM ^posts 
WHERE postid > $myurl
AND type='Q'
ORDER BY postid ASC
LIMIT 1";
 
$next_q = qa_db_query_sub($query_n);
 
while($next_link = qa_db_read_one_assoc($next_q, true)){
 
$title = $next_link['title'];
$pid = $next_link['postid'];
 
echo '
<A HREF="'. qa_q_path_html($pid, $title) .'" title="'. $title .'" STYLE="float:right">Next Question &rarr;</A>';
}
 
}
 
// adding next and previouls question links after all answer. This can be place anywhere you want just call get_prev_q() and get_next_q() functions
function a_list($a_list){
qa_html_theme_base::a_list($a_list);
$this->get_prev_q();
$this->get_next_q();
}
 
I would like to know if this code can be better.

 

by
Great work, that was an older request which finally exists as plugin ! Thank You..
by
the plugin page is missing and could not get the code work on infinity theme... after testing to enter the code on multiple places my footer disappear.

might be me doing it wrong or the code is not working
...