doushi6947 2013-10-24 22:10
浏览 29
已采纳

MySQL查询中的PHP变量从列表中爆炸

I have a section of code that I can't get to work. the $num variable needs to be passed to the mysql query so it update the latest record with the $num.

The code works when I set $num_d = '1234';

How can I pass the $num variable to the query statement

 $test_message ="$full, $t_phone_number, $f_phone_number";

//explode sms message into variables
list($name, $status, $timecode, $latitude, $longitude, $num, $city, $state, $t_phoneb, $t_phone, $f_phone) = explode("," , $test_message);

print_r(explode(',', "$test_message"));

$num_ext = explode(",", $test_message);
$num_d = (string)$num_ext[5];

// Update database table
 mysql_query("UPDATE msg SET timecode_off= '$timecode' WHERE (num= '$num_d') ORDER BY id DESC LIMIT 1");
  • 写回答

5条回答 默认 最新

  • dongxian1699 2013-10-24 22:34
    关注

    Your code looks to buggy, also three lines doing the same

    /* Here, what is the $full format? I looks like a string with coma separated */
    $test_message ="{$full}, {$t_phone_number}, {$f_phone_number}";
    
    /* Mapping the array without spaces */
    $array = array_filter(array_map('trim', explode(',', $test_message)));
    
    /* Update database table */
     mysql_query("UPDATE msg SET timecode_off= '{$array[2]}' WHERE (num= '{$array[5]}');") or die (mysql_error());
    

    I guess, this code must work, however I don't know the $full structure, another think to take care is the ORDER BY restriction, that is for SELECT clause, no for UPDATE clause, probably you need a WHERE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路