dongxing2692 2012-07-21 22:21
浏览 27
已采纳

使用数组选择获取MySQL错误

I am having trouble with one of my arrays. For some reason, whenever I test it I get this error:

  • Unknown column 'ext_token' in 'where clause' if I have the or die mysql error on,
  • or I get Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given, if I take it out.

I’m not sure whether it has something to do with the fact that the first columnName in the array is ext_token, but I thought I would get rid of that by the if below.

Here is the code for the array:

   $mat_total = array();

foreach ($result_array1 as $columnName => $columnData){

   if($columnName != "ext_token" || "ext_token_child"){
           var_dump($columnName);
           $mat_sql = mysql_query("SELECT * FROM materials WHERE mat_token = $columnName");
           $mat_array = mysql_fetch_assoc($mat_sql);
           $material_tok = $mat_array['mat_token'];
           $material_price_unit = $mat_array['material_price_per_unit'];


           $total_mat_price = $material_price_unit * $columnData;

           array_push($mat_total, "$material_tok => $total_mat_price");

   }
   else{
       echo "hello";    
   }

}

Thanks for any and all help.

Edit: in terms of the array here is a clearer version of it

Column name: ext_token Column data: roof
Column name: ext_token_child Column data: felt
Column name: concrete Column data: 4
Column name: cement Column data: 3
Column name: sand Column data: 2
Column name: wood_4_2 Column data: 4
Column name: wood_8_2 Column data: 2
Column name: felt Column data: 2

or there is this:

array(8) { ["ext_token"]=> string(4) "roof" ["ext_token_child"]=> string(4) "felt" ["concrete"]=> string(1) "4" ["cement"]=> string(1) "3" ["sand"]=> string(1) "2" ["wood_4_2"]=> string(1) "4" ["wood_8_2"]=> string(1) "2" ["felt"]=> string(1) "2" }
  • 写回答

4条回答 默认 最新

  • dongyong3223 2012-07-21 22:51
    关注

    You forgot to enclose the value with single quotes. It should be like

    WHERE mat_token = '$columnName'"

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

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能