doumaoao0182 2014-12-08 23:03
浏览 50
已采纳

将数组转换为句子中的字符串[关闭]

I am just trying to convert some user id's to usernames in from an sql database. I know I shouldn't be using mySQl. I plan on switching over to PDO shortly...

  $getuseridsquery= "SELECT users.username FROM users WHERE users.id IN(". implode( ",", $uids) .")";
  echo $getuseridsquery;
  $getuseridsresult = mysql_query($getuseridsquery);
  $getuseridsresult1 = mysql_fetch_assoc($getuseridsresult);
  var_dump($getuseridsresult1);
  echo $getuseridsresult1;

  print '<p>Conversation between ';
  print implode(', ', $getuseridresult1) . ' and ' . $last;
  echo '.</p>';

I am getting:

 array (size=1)
  'username' => string 'ambe5950' (length=8)

when I var dump, so I just need to figure out how to convert that to the sentence below.

Sincere thanks for any help. It is greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dougou6213 2014-12-08 23:07
    关注

    The username part of that output is the index/key in your array. This is akin to what other languages call a Map or a Dictionary, but PHP allows for non-integer indexes in arrays. Simply put, you need to access the value via its index, which in this case is "username":

    $username = $getuseridsresult1['username'];
    echo $username; //prints "ambe5960"
    

    Also if you're not moving to PDO yet, then you should at the very least change mysql_* to mysqli_*.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀