Page 2 of 2

Posted: Thu Oct 04, 2007 6:35 pm
by shivam0101

Code: Select all

krsort($match_list);     
                   $result_details.="<table width='40'></table>"; 
           foreach($match_list as $match_num=>$matches) {
          
           $result_details.="<tr><td>Numbers matching $match_num characters are:</td></tr>";
           foreach($matches as $match) $result_details.="<tr><td>$match</td> <td><input type='text' name='matchnumber[$match]'></td></tr>";
           }
          $result_details.="</table>";
If i post, i am getting only one number for each matching.

Example:

winning_number:
ABCDEFG123


guess_numbers:
MMMMMMMMM3
NNNNNNNNNM2
OOOOOOOOO2

Here there are 1 matching numbers. If i put values in their relevent textboxes, say 1,2,3 I am getting only 3. Another thing is, how do i pass their respective values when i am in the edit mode?

Posted: Fri Oct 05, 2007 1:42 am
by Stryks
Ummm ... :?

Sorry, I'm really confused.

If you're asking what I think you're asking, then you are having problems with a 'guess submission' form. Like ...
Enter your three guesses

Guess 1 _________
Guess 2 _________
Guess 3 _________
But when you are reading the values you are only actually getting the value from Guess 3?

You might have given each of the input boxes the same name. Try naming them all alike.

Code: Select all

<input type="text" name="guess[]">
You should be able to then loop through them.

Code: Select all

foreach($_POST['guess'] as $guess) { echo $guess }
I don't understand your reference to edit mode. You want to carry the values back to a form to edit? Perhaps save the guess array to a session and when redrawing the form setthe text box value to what is in the session if it is set.

Of course, none of this might be what you meant. Code samples and another run at the explanation might help if I'm missing your purpose here.

Cheers

Posted: Fri Oct 05, 2007 3:13 am
by shivam0101
I have a table in which randomly some values will be entered for a question.

guess_numbers

guess_number_id (pk, auto inc)
question_id
random_answers


The right answer will be entered later in another table.

question_table
question_id (pk, auto_inc)
right_answer

once it has been entered, i have to match with guess answers and display the results like,

matches 7
ABCDEFG
ABCDEFG

matches 6
ABCDEFX
ABCDEFX

..............

till
matches 0
1234567

Your code worked fine, but to edit i have to pass the values to textbox, which i am not able to do.

Posted: Fri Oct 05, 2007 7:15 am
by Stryks
My friend, you have an awesome ability to explain something and leave me more confused. :D

I have to ask .... what is it that you are actually trying to make. Somehow I feel like this may be one of the weirdest things of all time. You have a secret question / answer combo stored in a database, but you also have a series of guesses. The guesses are displayed, and you want to what? Let the users modify the guesses? For what purpose? Do you realize that they will be able to fake a 'perfect match' really easily? And then what? Guesses are stored back to the database ... or are they always the same?

It seems illogical to create what looks like a 'mastermind' style system that doesn't enforce any rules other than all characters from the master code must exist in the guess. You have 7 digit codes, so assuming that you enforce guesses to also be 7 characters, then there would be thousands of combinations that would *appear* a perfect match with a score of 7 matches. Maybe hundreds of thousands. I'd work it out but I'm crap at maths.
:lol:

Anyhow, it would appear from you sample numbers in your last post that you are passing multiple guesses which are the same. Because you are using the guess as the key in the $_POST array, a duplicate will overwrite the previous one. When creating an array, $_POST or otherwise, you must ensure that your keys are unique.

Assuming this is in fact your problem .... the following should work.

Code: Select all

foreach($matches as $id=>$match) $result_details.="<tr><td>$match</td> <td><input type='text' name='matchnumber[$match|$id]' /></td></tr>";
How'd I do?