Hello; Is it possible to pass the output of echo to a new variable? What I mean is something like that: $a = '1'; $b = (echo $a);
no becouse echo() doesn't return any value. You can do something like this: $foo = 'foo'; echo $bar = $foo; //foo echo $bar; //foo PHP:
no, anyway I don't get the reason to do that, the output of "echo $a" is the same as "echo $b" if you assign $a value to $b like this $b=$a if you need the var dump, do this: $b=var_dump($a);
The problem is; User X answers a question on a particular grammar subject, let's say pronouns and if the answer is correct, the column value corresponding to the correct answers will increase by one and vice versa. Each subject has its unique code, pro for pronouns, adj for adjectives etc. The column name for correct answers on pronouns is pro_c; and for incorrect answers is pro_i. The script is able to determine the subject using GET or POST method. Therefore, I leave it as a variable, $subject. What I want is to be able to update the columns in accordance with the answers. For correct answers, the column $subject_c must increase by one and for incorrect ones the column $subject_i will increase as due. Now, the question is how to create the variables $subject_c and $subject_i.
i think that _:codefan:_ answered your question already. first you put it in another variable and then you echo it.
You would create $subject_c and $subject_i at the point where your script determines if the answer is correct or incorrect. This I assume happens when the user hits submit. Then you return these values on the resulting page. It almost sounds like you are trying to update the columns as the user answers the questions in real time. PHP requires a call to the server (submitting the page or calling a new page) so JavaScript would be your answer there.
Thank you very much. I managed to solve the problem. It was much simpler than I thought. Here it is; $subject = $_POST['subject']; $c = "_c"; $i = "_i"; $e = "$subject{$c}"; //gives me $subject_c, the cell for correct answers $f = "$subject{$i}"; //gives $subject_i, the cell for incorrect answers Then I use the variables $e or $f while updating the cells $subject_c or $subject_i.