Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

php產生奇怪的結果....請大大幫忙解答

我寫了一段捉值的程式...我把結果echo出來...卻產生Resource id #3

程式如下:

$abc=mysql_query("Select remnant From storage where No='$No'");

echo $abc;

會產生Resource id #3是什麼問題呢??

Update:

以下是我的程試碼...請大大幫忙看看...我找了好久還是找不出哪裡有問題$No=trim($val[12]);<--這是從別的網頁傳過來的值...

Update 2:

mysql_query("Insert Into material Values('', '$Fn', '$Sn', '$Paper', '$year', '$month', '$date', '$Type', '$Size', '$Controller', '$Amount', '$Status', '$use')");<---這行執行沒問題

Update 3:

但下面接的這行...我echo值出來就會出現Resource id #3

$abc=mysql_query("Select remnant From storage where No='$No'");

echo $abc;是什麼問題??請大大幫忙解答

1 Answer

Rating
  • ?
    Lv 6
    1 decade ago
    Favorite Answer

    $abc=mysql_query("Select remnant From storage where No='$No'");

    echo $abc; 結果會是 Resource id #3

    那是當然的,這不是什麼錯誤啦~~

    那只是MySQL的連線編號而已

    為什麼呢??因為

    $abc=mysql_query("Select remnant From storage where No='$No'");

    其實是等於

    mysql_query("Select remnant From storage where No='$No'")

    那他會告訴你什麼,當然說他已經連上線了,就是這樣而已

    事實上,你只要再加一行就有作用了

    $number = mysql_num_rows($abc); //這一行就是計算所得到的筆數

    如果上面那個 No 欄位是唯一值的話(key)

    那再加

    $fo = mysql_fetch_object($abc);

    $remnant=$fo->remnant;

    echo $remnant;

    這樣就會得到 remnant 欄位的 資料

    如果 No 欄位不是唯一值(多筆資料)

    那就要加迴圈,就可以把資料一筆一筆讀出來

    像這樣

    for ($i=1; $i<=$number; $i++) {

    $fo = mysql_fetch_object($abc);

    $remnant=$fo->remnant;

    echo $remnant."<br>";

    2006-09-24 01:41:23 補充:

    剛剛最後少了一個迴圈結束for ($i=1; $i<=$number; $i++) {$fo = mysql_fetch_object($abc);$remnant=$fo->remnant;echo $remnant."<br>";}

    Source(s): 自己~~~
Still have questions? Get your answers by asking now.