duanhu2414 2013-07-30 21:58
浏览 7
已采纳

PHP⎼不要围绕数字

I have to put 2 id-s together from $_POST then I want to explode them, example:

My id-s are 38 and 310. I made the id-s to this id = "38.310" in my html file.

After $_POST I want to explode the id-s:

$id=$_POST['id'];

echo($id);  // Gives 38.31
$new_id = explode(".", $id);

echo($new_id[0]); // Gives 38
echo($new_id[1]); // Gives 31

Is the a way to get these id-s not rounded?

I need the 38 and the 310! The id 310 can be also 1003000 ...

EDIT:

function dostuff(document, message, id, action) {
        var eingabe;
        eingabe = confirm(message);
        if (eingabe === true) {
            document.msgform.action.value = action;
            document.msgform.id.value = id;
            document.msgform.submit();
        } else {
            return true;
        }
        return false;
    }

LINK

<a href="#" onclick="dostuff(document, 'MESSAGE',<?php echo($row['vID']);?>.<?php echo($row['id']);?>,'FITTER_fitter_repaired');" class="button small red" >ACTION</a>

$row['vID'] = 38

$row['ID'] = 310

and my submit looks like this

<form enctype="multipart/form-data" name="msgform" action="" method="post">
    <input type="hidden" value="" name="action"/>
    <input type="hidden" value="" name="id"/>
</form>
  • 写回答

4条回答 默认 最新

  • dongyan2469 2013-07-30 22:23
    关注

    I don't know what the function dostuff is doing, but Javascript is the evil one. Put quotes around the values. In this way there is no casting involved and it gets posted as string.

    <a href="#" 
    onclick="dostuff(document, 'MESSAGE', '<?php echo($row['vID']);?>.<?php echo($row['id']);?>','FITTER_fitter_repaired');" class="button small red" >ACTION</a>
                                          ^                                                    ^                             
    

    EDIT:

    But I also think that Lee's solution would be better. Just make 2 input fields and fill them in your dostuff function. You could also give id's to the input fields to make it easier to fill.

    <input id="id1" type="hidden" value="" name="id[]"/>
    <input id="id2" type="hidden" value="" name="id[]"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?