Insensus 52 Junior Poster

The dereference (*) operator has lower priority than the member (.) operator so you need to add brackets:

(*str).length()
Insensus 52 Junior Poster

What rubberman said is actually wrong.
In a multiset an element's key is itself so you need to specify only one type.

Now I'll try to explain to you why you get this error:
When you use a function that's defined from a template, your compiler will at compile-time create an actual function from your template definition for the required type.
Now because your instantiation happens with an int the multiset inside your function will be a multiset<int> and therefore multiset<int>::insert(const string&) will generate an error even though you will be preventing that statement from ever happening at run-time. Your compiler can't know that and therefore can't compile.

You COULD do this with templates, but then you'd need to create a new specialization for every different type of variable which is pretty much the same amount of work as just making three different functions.

Insensus 52 Junior Poster
long2ip();

:P

dalip_007 commented: excellent +2
Insensus 52 Junior Poster

strpbrk effectively returns the part of the string starting at the first occurence until the end of the string.
If you pass such a string to atoi it will return the first numeral and ignore everything after that.
Note that this numeral doesn't have to be 1 digit long but can be many more and you're not dealing with this in the right way because what happens is this:

input: 12345

ptr: 12345
atoi(strpbrk()): 12345

ptr+1: 2345
atoi(strpbrk()): 2345

ptr+1: 345
atoi(strpbrk()): 345

And so on.

You could get the length of the number simply by checking to what power of 10 it's greater or equal to, but that's not a proper way to do it since every number with some leading zeroes (which are discarded by atoi) would make your program fail.

The best approach in my eyes would be to add another loop after you've found a digit:
Save the first digit of a numeral (ptr[0]) in an int and then loop the next characters until you find a non-digit simply while multiplying the old int by 10 and adding the new digit each time you do find a new one.

Insensus 52 Junior Poster

Hmm that's maybe because I just created that from the top of my head and checkboxes don't actually have a visible background.
In that case, replace the

background: #0f0;

by

border: 1px solid #0f0;

Which should give the checkbox a green border.
It's not the most elegant way to do this, but then again it was just for demonstration.

Insensus 52 Junior Poster

Well if you really want to keep the table format as you have it right now just replace the

$i == $info['Ans_Answer']

with

$info['Ans_Answer'.$i]

and

$i == $info['Que_Answer']

with

$info['Que_Anwer'.$i]
Insensus 52 Junior Poster

Nope you've just got me back. :)

If the number of choices doesn't differ (always 4) then this approach is good enough so I won't talk about that unless you want me to of course.

Now this still leaves one way to make your system a little less complex by changing the 4 fields Answer1-4 to one Answer field which simply contains an integer refering to the correct answer.
The same can then be done for your Answers table so you'd get something like:

Que_Question_ID= 1
Que_Question= What is your name
Choice1= Nick
Choice2= John
Choice3= Lisa
Choice4= Lilly
Que_Answer= 4
Ans_Answer_ID= 1
Ans_Answer= 4
Question_id=1
User_ID= 3

This allows for some simplifications in your PHP code:

while($info = mysql_fetch_array( $sql)) {
    echo " <strong> $intNumber, {$info['Que_Question']} </strong><br />\n";

    // Loop the possible answers instead of writing everything manually
    for($i = 1; $i <= 4; $i++) {
        echo "<input type=\"checkbox\" name=\"choice{$i}[]\"";

        // Make the checkbox checked if this is the submitted answer number
        echo ($i == $info['Ans_Answer']) ? " checked" : "";

        // Give it a green background if it's the correct answer
        // This is something you'd want to change yourself, just showing how it's done
        echo ($i == $info['Que_Answer']) ? " style=\"background: #0f0;\" " : "";

        echo " /> {$info['Que_Choice'.$i]} <br />\n";
    }
    $intNumber++;
}

I hope this is enough to at least get you started.

Insensus 52 Junior Poster

If in your while loop you know which one is the one you want to display add 'selected' to the <option> like so:

<option value="..." selected>

For which you can use the short if-else:

<option value="..."<?php echo ($selected) ? " selected" : ""; ?>>
Insensus 52 Junior Poster

Could you maybe give an example question and choices showing what each table-field represents in a question? Because I see you're not using the Que_Answer1-4 for example.

Insensus 52 Junior Poster

Maybe you can post a little more about the structure of your table, maybe some sample data?

I can't really visualize what you're trying to accomplish right now.

Insensus 52 Junior Poster

http://php.net/manual/en/function.header.php

This lets you change the HTTP headers which is probably the best way to redirect someone.
Something like:

Header("Location: /$directory");

Be sure to put it early in your document, before any output is generated, or you will get an error because you can't change the headers anymore.

Insensus 52 Junior Poster

Maybe this?

testPF(std::move(a), std::move(b))