开发者

PHP MySQL string showing up as an integer

I have a field called 'score' in a database table that an ajax call is adding values to.

The query below causes it to add values of 1 and 2 under 'score'. It should be looking for "$usrscore1" and "$usrscore2" in my ajax call but it seems to just see the integers (1 and 2) in $us and incorrectly post them as the values under 'score'.

for ( $counter4 = 1; $counter4 <= 2; $counter4 += 1) {

    $mess4 = $messages + $counter4;
    $us = $usrscore + $counter4;

    mysql_query("INSERT INTO messages" . $counter4 . " (`score`)
            VALUES ($us)",$dbconn);
}

If I change:

$us = $usrscore + $counter4;

to

$us = $usrscore1;

it correctly looks for $usrscore1 in my ajax call and puts the correct value in the database field under 'score'. But I need it to work in the for loop so just writing it out as $usrscore1 won't work, even though it reads it correctly that way.

Just in case it helps to see it, here's what the ajax call looks like:

$('#rateplugin' + instance).raty({
                half: true,
                start: totalavgRounded,
                click: function(score){

                        $.ajax({
                            type: 'POST',
                            url: 'backend.php',
                            data: "usrscore"+instance+"="+score+"&action=postmsg",
                            success: function(xml) {
                                $.fn.raty.readOnly(true,'#rateplugin' + instance);
                            }
                        });
                    return false;

                } // end click
            }); // rat

Update:

I may have not been very clear. I set the loop up to only make 2 database tables, but I did that really just for testing purposes. In reality, once this is live, there could be thousands of these to create which is why I'm doing it with a loop. Would the URL variable still be a good solution here? I'm not exactly sure how I would implement it.

My main point of absolute开发者_JAVA百科 confusion here is that that no matter how I broke up the variable integer from $usrscore it would always ignore the $usrscore part and only see the integer and then just use that as the final value which will always be wrong. Is there something weird about the VALUE MySQL bit that does this? Does anyone have any ideas as to why it is doing that and how to get around it? If that URL variable idea might work, could you please give me some direction into its application here?


from what i can see, you only have limited $usrscore1 and $usrscore2. i suggest you put a single variable $usrscore and populate it based on the parameter in the url.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜