为MySQL结果设置用户变量

时间:2015-04-15 17:44:15

标签: php mysql

我需要帮助设置MySQL结果的用户变量。

SELECT ptype, COUNT(ptype) FROM `TABLE 2` GROUP BY ptype ORDER BY COUNT(ptype)

我想为所有类型的结果值创建一个用户变量(TD = 5 ,DT = 13 ,...等)

我该怎么做?

DW



<?$connector=mysqli_connect("localhost","", "","");

						
$res2=mysqli_query($connector, "SELECT ptype, COUNT(ptype) FROM `TABLE 2` GROUP BY ptype");


for (i = 0; i <12; i++) {
$carrier[i] = while ($row=mysqli_fetch_array($res3)) {echo $row['COUNT(carrier)'];}
						}			
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

尝试:

$ptype = array();
if($res2=mysqli_query($connector, "SELECT ptype, COUNT(ptype) AS pnum FROM TABLE 2 GROUP BY ptype")){
  while($row=mysqli_fetch_array($res2)) {
    $ptype[] = $row['pnum'];
  }
} else {
  printf("Error: %s\n", mysqli_error($connector));
}