duangong1979 2013-06-13 15:23
浏览 13
已采纳

如何以相同的顺序放置两个数组?

I'm pulling two arrays from my database. One of them is from the friends table, and the other is from the members table.

What I'm trying to do is display the usernames of the friends on the profile. That's done, but now I'm trying to make links to the person who has that username's profile (click on userName to go to userName's profile). The friends array ($friendsarr) has all of the ID's of the friends, and the username array ($friendunamearr) has the usernames that match the ID's. However, they are not in the same order.

If I forgot to mention earlier, the members table has an ID field. That's how I'm pulling all of the usernames.

For example, let's say there's user1 and user2. User1's ID is 1. User2's ID is 2. When I click on the link to User1's profile, it takes me to User2's profile, and vice versa.

Is there a way to put them in the same order?

  • 写回答

2条回答 默认 最新

  • dongzhuan1185 2013-06-13 15:32
    关注

    You can join the two tables before you even put them in an array. Then the data is already matched up for you.

    http://www.w3schools.com/sql/sql_join.asp

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟