Counter variable PHP

Asked

Viewed 828 times

1

Good staff,

I have a form in a file PHP to fill a leaderboard. And wanted my form asks itself something like, "Athlete’s number in the ___" position, where the number of the position in the __.

For example: The form "What’s the athlete’s number in first place" and then form and click Submit after clicking the form "What is the athlete’s number in 2nd place" and we click "What is the athlete’s number in 3rd place" and so on. But when we leave the browser go back to where it was, if the form be the "What is the athlete’s number in the 5th place" and if we close the browser when we return to the site the form stay in the same place.

And I’m more given to Java so I thought I could do a counter variable. But I don’t know how and I went to search and I didn’t find anything useful.

Does anyone know how to do that in PHP or knows how to do something similar that can indicate me a website or what to do?

There’s my form

<div id="formT">
	<form  method="post" action="alterarN.php">
		<p>Qual e o Dorsal do atleta em _º lugar?</p>
       <!--nesse _ deve estar o lugar-->
		<p><input type="text"  name="numero" required/></p>
		<input type="submit" value="Registar" id="registar"/>
	</form>
	</div>

  • Put your code there Bruno, so we can help you better.

  • @Diegosantos already has code there.

  • the counter must persist per browser session? per user? must be global?

  • @Penalty the meter must persitir by the number of athlete enter in the database

  • You want to create a combo, the positions of the athletes to select?

  • @What I want is that in my form As I insert athletes, the "___" of the "Which is the number of the athlete who was in __º place" will change. For example: "What is the number of the athlete who was in first place" and I enter the number and when to do Submit change to "What is the number of the athlete who was in 2nd place" and so on

Show 1 more comment

1 answer

2


mysql_select_db($bd, $coneccao);

$query = "SELECT lugar FROM atletas";
$result = mysql_query($query, $coneccao) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$lugar = row['lugar'];
$lugar+=1;


<div id="formT">
    <form  method="post" action="alterarN.php">
        <p>Qual e o Dorsal do atleta em <?php echo $lugar; ?>º lugar?</p>
       <!--nesse _ deve estar o lugar-->
        <p><input type="text"  name="numero" required/></p>
        <input type="submit" value="Registar" id="registar"/>
    </form>
    </div>
  • Failed to increment 1 variable $lugar and also set 0 if the query return is null.

  • Editado! I haven’t tested it, but if it is null and make $lugar+=1; the value becomes 1, theoretically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.