Creating A Question and Answers page.
Moderator: General Moderators
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Creating A Question and Answers page.
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?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
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?
(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
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
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
Do you want to write it from scratch or use something like Wordpress to achieve the same thing?
(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
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
http://www.cheatmasters.com/qa/19349/St ... _2_qa.html
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
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.
(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
How could I start with creating something like this, or do you know any templates similar, as I'm fairly new to PHP?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
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.
(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
Do you know any free templates I could use to set me off?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
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.
(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
What PHP and MySQL would I need?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
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.
Use the PDO or mysqli extension for database access.
(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
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.
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>- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Creating A Question and Answers page.
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>(#10850)
- chris98
- Forum Contributor
- Posts: 103
- Joined: Tue Jun 11, 2013 10:47 am
- Location: England, United Kingdom
Re: Creating A Question and Answers page.
How could I make it hidden by default?