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条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料