Page 1 of 2

Creating A Question and Answers page.

Posted: Sat Jun 15, 2013 3:23 am
by chris98
Hello, I would like to create a Question and Answers page on my site, where people can ask questions, and other members can respond.Does anyone know how to?

Re: Creating A Question and Answers page.

Posted: Sat Jun 15, 2013 12:03 pm
by Christopher
It sounds the same as a blog post with comments. You could use something like Wordpress for that. Do you want people to be able to vote for the answers like on StackOverflow?

Re: Creating A Question and Answers page.

Posted: Thu Jun 20, 2013 11:04 am
by chris98
It doesn't really matter, as long as anyone at all, (even guests) can leave a question or answer that an Administrator can remove if necessary

Re: Creating A Question and Answers page.

Posted: Thu Jun 20, 2013 11:18 am
by Christopher
Do you want to write it from scratch or use something like Wordpress to achieve the same thing?

Re: Creating A Question and Answers page.

Posted: Thu Jun 20, 2013 11:30 am
by chris98
I just want something that is easy to moderate, and fairly easy to change styles.I think that it would be easier to use a template, but as long as you don't have to login specifically to just view it, then i'm fine.Also, preferably if possible I would like a theme similar to the one below.

http://www.cheatmasters.com/qa/19349/St ... _2_qa.html

Re: Creating A Question and Answers page.

Posted: Thu Jun 20, 2013 1:42 pm
by Christopher
Submitting a question or answer looks like a popup that is a PHP script that adds it to the database. The page seems to load maybe 50 questions plus their answers. Then it uses CSS and Javascript to show/hide the answers.

Re: Creating A Question and Answers page.

Posted: Fri Jun 21, 2013 9:37 am
by chris98
How could I start with creating something like this, or do you know any templates similar, as I'm fairly new to PHP?

Re: Creating A Question and Answers page.

Posted: Sat Jun 22, 2013 10:08 am
by Christopher
It's mostly done with CSS and Javascript, I would start there. All the PHP does is provide the question and answer records from the database.

Re: Creating A Question and Answers page.

Posted: Sat Jun 22, 2013 10:24 am
by chris98
Do you know any free templates I could use to set me off?

Re: Creating A Question and Answers page.

Posted: Sat Jun 22, 2013 7:29 pm
by Christopher
No, I don't know any templates. You could take a look at something like the jQuery hide()/show() methods. It should be pretty easy to first hide all the answers by making them all the same CSS class. Then show the ones that go with a question on a click event.

Re: Creating A Question and Answers page.

Posted: Sun Jun 23, 2013 3:07 am
by chris98
What PHP and MySQL would I need?

Re: Creating A Question and Answers page.

Posted: Sun Jun 23, 2013 12:59 pm
by Christopher
I would first write the HTML/CSS/Javascript to show a page with one question with answers. Then add PHP to fetch questions and their answers. Put a PHP loop around the one question with answers and fill in the text, etc. with the values from the database. Once you have that working, then you can add pagination -- only fetching say 25 questions.

Use the PDO or mysqli extension for database access.

Re: Creating A Question and Answers page.

Posted: Mon Jun 24, 2013 10:14 am
by chris98
So far, i've come up with this, but could you tell me what is wrong here, as it's not hiding/showing the text?

The text on the button changes, but the actual text down the bottom doesn't.

Code: Select all

<input type="button" id="hide" value="Hide" onclick="return change(this);" />

<script type="text/javascript">
function change( el )
{
    if ( el.value === "Show" )
        el.value = "Hide";
    else
        el.value = "Show";
}
$(document).ready(function(){
  $("#hide").click(function(){
    $("p").hide();
  });
  $("#show").click(function(){
    $("p").show();
  });
});
</script>
<p>test</p>

Re: Creating A Question and Answers page.

Posted: Mon Jun 24, 2013 10:39 am
by Christopher
Remember to link to JQuery:

Code: Select all

<input type="button" id="mybutton" value="Hide" />

<script type="text/javascript">
function change( el )
{
    if ( el.value === "Show" )
        el.value = "Hide";
    else
        el.value = "Show";
}
$(document).ready(function(){
  $("#mybutton").click(function(){
	change(this);
	$("#mytext").toggle();
  });
});
</script>
<p id="mytext">test</p>

Re: Creating A Question and Answers page.

Posted: Mon Jun 24, 2013 10:53 am
by chris98
How could I make it hidden by default?