Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Konrad Pilch
Konrad Pilch
2,435 Points

PHP When do i use ?n=1 ?

HI,

WHen do i use ?n=1 . Im i am making a quizz game, why or how is this useful or affected or rather why is this there?

Hey Konrad! Can you post the code in question?

Konrad Pilch
Konrad Pilch
2,435 Points

Its this

<a href="question.php?n=1" class="start">Start Quiz</a>

2 Answers

Jose Soto
Jose Soto
23,407 Points

That is how you pass your script a GET variable. For example, if this link is clicked

<a href="question.php?n=1" class="start">Start Quiz</a>

You can grab the value of 'n' within you PHP script. For example:

<?php
/**
 * This is question.php
 */

echo $_GET['n'];/// Output = 1

Likewise, if you click on this link:

<a href="question.php?n=Hello" class="start">Start Quiz</a>

You will see this:

<?php
/**
 * This is question.php
 */

echo $_GET['n']; /// Output = 'Hello'
Konrad Pilch
Konrad Pilch
2,435 Points

Ahaaa so its like the "n" stand for and then i assign the value of it somewhere?

Or because this is connected to database with "choices" and "questions", this will conect to a database of questions "n" and then asign all the questions that have the number of id "1" ? something in that way?

Konrad Pilch
Konrad Pilch
2,435 Points

Or rather, the n is an assigment whcih if i put n=1 whill bring all the id's of the question 1 and if this is n=2 will bring all the id's of question 2 right?

Jose Soto
Jose Soto
23,407 Points

That's right. You got it.