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

报告相同问题?

悬赏问题

  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭