簡體   English   中英

mysql_query不顯示所有查詢

[英]mysql_query doesn't show all query

我想在cc_did_use中顯示所有不同的id_did

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;
}

我有兩個id_cc_card="31" ,一個值為id_dd="14" ,另一個為one = "13"但結果僅顯示第一個。

我怎樣才能展示他們兩個?

然后我還有另一個功能

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/>';
}
}

當我運行getdidbycc函數時,它返回兩個值13和14,如何從這兩個值中獲取數字呢?

您正在獲取結果並檢查if僅執行一次的if條件。

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

您必須獲取結果,直到結果數組中有值為止。 因此,嘗試使用while循環,

 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

首先嘗試使用mysqlipdo代替mysql否則您將在更新版本的php中遇到問題

根據您的代碼$ text值由於循環而被覆蓋,因此請使用類似這樣的數組

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

return $text;

或者您可以只返回完整的數據作為return $row;

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

將上面的行更改為此

while($row = mysql_fetch_array($result)) 
    {
    echo $row['id_did'].'<br/>';

    }

使用這樣的while循環: http : //php.net/manual/en/function.mysql-fetch-array.php

Mysql Fetch數組僅返回當前元素

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM