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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致