3
I am a beginner in programming and would like to know how I would make mine $id = 1, turn 2, 3 and so on. The code at the end, means that it needs to compare that value and only then occurs a $id++
. I know I need to insert into one while
, but I don’t know how to put.
It would be like, every $Row would be a letter, I put nine just to test. It is a game in super trump style, IE, at the beginning will appear only 1 (one card), and the person will select his attribute, this is done through the $_POST("Submit")
. After the person clicks, this attribute will compare to another attribute, where I put that ($select > 10
) just as an example. Next, the $id=1
needs to turn 2, for the game to continue until arriving $id=9
.
Yes! It’s a card game, like Super Trump you know?! The rule is very simple, because the player even winning or losing, his card has to change. What happens is that each letter, I inserted there by $row[1]
. Then after making this comparison, which is only for testing (Why compare with another card I already managed to apply), will go to the next card, which would be $row[2]
. And that happens until you get to $row[9]
.
It gave to understand better?
I do not want to play all select at once on the screen, but rather appear only one, and then, after this comparison made by button("Submit"), appear the $id=2
and so on.
In short, what I need is for you to start with 1, and once you make the comparison and click on the button, the next "screen" is 2.
include ("connect.php"); //Conexão Banco
$sql = mysql_query("SELECT * FROM card");
$id = 1;
$row[1] = mysql_fetch_array($sql);
$row[2] = mysql_fetch_array($sql);
$row[3] = mysql_fetch_array($sql);
$row[4] = mysql_fetch_array($sql);
$row[5] = mysql_fetch_array($sql);
$row[6] = mysql_fetch_array($sql);
$row[7] = mysql_fetch_array($sql);
$row[8] = mysql_fetch_array($sql);
$row[9] = mysql_fetch_array($sql);
$pic = $row[$id]["Photo"];
$rk = $row[$id]["Ranking"];
$tt = $row[$id]["Tittles"];
$st = $row[$id]["Started"];
$ya = $row[$id]["Years Active"];
if (isset($_POST["Submit"])){
if (!empty($_POST["game"])){
foreach ($_POST ["game"] as $selected) {
if ($selected > 10) {
echo "win";
}
}
}
}
Thanks in advance.
You can do a for().. would have a link that will click to go to the next page?
– Sr. André Baill
I can’t understand where you’re going.... Can you explain the situation better?
– Sr. André Baill
Explain better what is the purpose of this code ... it looks like some kind of card game ... what is the rule? the player gets 9 cards and what happens?
– rray
Remember that mysql_* functions are obsolete since PHP 5.5 and will be removed from PHP soon. Prefer to use Mysqli or PDO. See more here: http://www.ultimatephp.com.br/php-por-que-nao-utilizar-funcoes-mysql
– Beraldo
@Philip added text of the answer you had put. I deleted because it was not an answer. Can you [Dit] the question and see if the text is right? So we can help better.
– Sergio
Problem-free!!!
– Felipe