dongwo6477 2013-07-17 08:30
浏览 19
已采纳

如何在php中从mysql数据库中将值存储到数组中

The following is my scenario

i have the following databases

employee(e_no,e_name,e_contact,e_mail)
project(p_no,e_no,p_name)
project_assigned(id,pno,eno)
task(id,pno,tasks)

Now I have two particular files called employee_data_sheet.php and addtask.php I want to accomplish the following: When I post a task to addtask.php I want to view which employee has got the task in which project in employee_data_sheet.php

Following is the code snippet: (my addtask.php is working fine error in employee_data_sheet)

$query34="SELECT p_no FROM project_assign WHERE e_no='$empno'";
$res34=  mysql_query($query34);
while($row34=  mysql_fetch_array($res34))
{
  $pnum=array();
  $pnum=$row34['p_no'];
  $query35="SELECT p_name FROM project WHERE p_no='$pnum'";
  $res35=mysql_query($query35);
  while($row35=  mysql_fetch_array($res35))
  {
    $prname1=array();
    $prname1=$row35['p_name'];
  }
}

The problem is that I am not able to store the result of query to an array with comma separation. Please help me to store the result of a query to an array with comma separation

  • 写回答

1条回答 默认 最新

  • douwu3763 2013-07-17 08:32
    关注

    You are using deprecated database access functions. However I believe you are trying to do this

    $prname1=array();
    while($row35=  mysql_fetch_array($res35))
    {
        $prname1[]=$row35['p_name'];
    }
    $string = implode(",", $prname1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题