doufulian4076 2013-10-30 19:11
浏览 31
已采纳

我如何从每一行mysql表的列中创建一个变量?

trying not to make a table with a ton of columns. instead making a few columns and a ton of rows (or records).

if i did this with a ton of columns i would know how to do this, but how do you do this with multiple rows/records?

i have a table with these fields:

id, product_category, product_name, quantity_range, discount_amt

there are going to be a lot of records, but i'll just shorten it to a few rows for this question.

lets say i had these records:

1    Post Card    4x6    5M to 9,999      0.007
2    Post Card    4x6    10M to 14,999    0.01
3    Post Card    4x6    15M to 19,999    0.013
4    Post Card    4x6    20M to 24,999    0.015
5    Post Card    4x6    Over 25M         0.019

now what i want to do is make a group of variables of all the values in just the discount_amt column.

so i select everything in table like so:

$pricediscountquery = mysql_query("SELECT * FROM pricing_discount") or die(mysql_error());

then loop through result/rows like this:

while($pricingdiscountrow = mysql_fetch_array( $pricediscountquery )) {
  //echo $pricingdiscountrow['product_category']." ";
  //echo $pricingdiscountrow['product_name']." ";
  //echo $pricingdiscountrow['quantity_range']." ";
  echo $pricingdiscountrow['discount_amt']." ";
  echo "<br />";
}

this displays all the values of the column in a single variable name. i don't want that. i wan't a variable for 0.007, a different variable for 0.01, a different variable for 0.013, a different variable for 0.015, and a different variable for 0.019.

how do i do that?

  • 写回答

2条回答 默认 最新

  • dprc88435 2013-10-30 19:14
    关注

    you can use an array:

    $i=0;
    while($pricingdiscountrow = mysql_fetch_array( $pricediscountquery )) 
    $myarray[$i++]=$pricingdiscountrow['discount_amt'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog