dt1888 2014-09-25 12:11
浏览 17
已采纳

mysql_query不显示所有查询

I want to show all distinct id_did in cc_did_use

function getdidbycc($cccard_from_sipcard){
    $result = mysql_query("SELECT id_did from cc_did_use where id_cc_card='$cccard_from_sipcard'");
    if ($row = mysql_fetch_array($result)) 
    {
    $text = $row['id_did'];
    }
    return $text;
}

I have two id_cc_card="31" and one that value has id_dd="14" and another one = "13" but result just show first one.

How I can show both of them?

and after that I have another function

function get_did ($p){

$result = mysql_query("SELECT did FROM cc_did WHERE id ='$p'");
while ($row = mysql_fetch_array($result)) 
{
 echo $row['id_did'].'<br/>';
}
}

when I run getdidbycc function , it returns two value , 13 and 14 , How I can get did numbers from this two values?

  • 写回答

5条回答 默认 最新

  • doufei8691 2014-09-25 12:12
    关注

    You are fetching result and checking in an if condition which will execute only once.

    if ($row = mysql_fetch_array($result)) 
    {
        $text = $row['id_did'];
    }
    

    You have to fetch the result until there is value in the resultant array. So try with while loop like,

     while($row = mysql_fetch_array($result))   // while there are records
     {
        $text[] = $row['id_did'];    // store the result in array $text
     } 
     return $text;    // return the array
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程