dongtui2029 2013-06-04 07:49 采纳率: 0%
浏览 51

PHP数组内爆

I am using a query to get all the column names from my database, then I am trying to display the results comma seperated, in quotation marks and in (). And also make variables out of them.(Take a look at the example at the bottom and you will probably understand) The Columns I have in my DB are:

ID  
Naam     
Email
Soort
Status

And I am using this to get them:

$strSQL = "select column_name from information_schema.columns where table_name='Klant'";  
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); 
$objResult = mysql_fetch_array($objQuery);

So I was wondering If there is any way to get the result displayed like this:

$vaaw       = array("(ID)", "(Naam)", "(Email)", "(Soort)", "(Status)");

And also like this:

$vervang    = array("$ID", "$Naam", "$Email","$Soort", "$Status");

I want to use this instead of typing the column names in my code because if I ever change the column name or add/delete a column then I will have to edit the codes again.

I have been looking for a way to get this for hours now but I just can't find anything to display it like this. I think it could be possible using the implode function but I couldn't find anything like this. I hope my question is clear but if not just ask for clarification!

Also, I know I shouldn't be using Mysql_ anymore but I am working on that and will change to PDO soon!

  • 写回答

1条回答 默认 最新

  • duankuaiwang2706 2013-06-04 07:56
    关注

    You want something like this:

    $data = array(
      "ID" => 1,
      "Naam" => 2,
      "Email" => "asd@mail.com",
      "Soort" => 4,
      "Status" => 5
    );
    
    echo '$vaav = array("(' . implode( ')", "(' , $data) . ')") ;' ;
    
    echo '$vervang = array("' . implode( '", "' , $data) . '") ;' ;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?