简体   繁体   English

如何以逗号分隔存储数据库值?

[英]How to store database values as comma separated?

here am trying to take the set of database values as comma separated and store it in a javascript variable. 这里我试图将数据库值集合为逗号分隔并将其存储在javascript变量中。 I tried doing it. 我试过这样做。 but i couldnt make them comma separated as the output comes all together. 但是我不能让它们以逗号分隔,因为输出总是在一起。 Please correct me where am doing mistake. 请纠正我在哪里做错了。

Notes : If the value of assignedto is empty. 注意:如果assignedto的值为空。 the staff names with flag 1 will get fetched from database. 带有标志1的员工姓名将从数据库中获取。 but in the script below it comes all together where i require them to be comma separated. 但在下面的脚本中它汇集在一起​​,我要求它们以逗号分隔。

 if(assignedto == "")
    {
    '<?php
        $val = mysql_query("select * from staff where flag='1'");
        $arr='';
        while ($row = mysql_fetch_array($val))
        {
        $arr = array($row['name']);
        $assign .= implode(',',$arr);

    ?>'
    assignedto = '<?php echo $assign; }?>';
    }

I am not sure, but you code seems to be wrong, have you tried this? 我不确定,但你的代码似乎错了,你试过这个吗?

if(assignedto == ""){
   <?php
   $val = mysql_query("select * from staff where flag='1'");
   $arr=array();
   while ($row = mysql_fetch_array($val)){
       $arr[] = $row['name'];
   }
   $assign = implode(',',$arr);
   ?>
   assignedto = '<?php echo str_replace('\'','\\\'',$assign); ?>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM