2013-12-27 00:32
浏览 36


I'm trying to run this MySQL code in PHP.

SELECT DISTINCT teamid FROM teammembers INNER JOIN teams WHERE = teammembers.teamid

If I run this code in SQL, I get around 20 different values, and I would like to save this unique values in an array so I can use them later.

So I'm using this PHP code:

$totalteams = mysql_query("SELECT DISTINCT teamid FROM teammembers INNER JOIN teams WHERE = teammembers.teamid");

Now I want to check if the code is working or not, so I did:

echo $totalteams;

And as result I got:

Resource id #5

I also tried with:

echo mysql_result($totalteams,0);

And it does work that way, but that count asks me for the row number, therefore it only displays one value, and I need all of them.

Can anyone help me?

图片转代码服务由CSDN问答提供 功能建议


 < 代码> SELECT DISTINCT teamid来自teammembers INNER JOIN团队WHERE = teammembers.teamid 

如果我在SQL中运行此代码,我会得到大约20个不同的值, 我想将这个唯一值保存在一个数组中,以便以后可以使用它们。


   $ totalteams = mysql_query(“SELECT DISTINCT teamid FROM teammembers INNER JOIN团队WHERE = teammembers.teamid”); 

现在我要查看 如果代码工作与否,我做了:

  echo $ totalteams; 

结果 我得到了:


我也尝试过: \ n

  echo mysql_result($ totalteams,0); 

它确实有效,但是这个数字要求我输入行号, 因此它只显示一个值,我需要所有这些值。

可以 一个人帮帮我?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douchen1988 2013-12-27 00:35
    1. you should look at using mysqli, mysql is obsolete in the latest php (5.5)
    2. you should really look on google, I'm sure this was answered at least a million times,
    3. try something like,

    while ($row = mysql_fetch_assoc( $totalteams )) {   
        print_r( $row );  

    解决 无用
    打赏 举报

相关推荐 更多相似问题