請教個問題 mysql記錄集不支援movenext方法嗎

來源:互聯網
上載者:User
function GetTags($device)
{
$sql = "select tagname from TagList where device='$device'";
$rs = mysql_query($sql);
while(! $rs->eof) //將記錄集儲存到二維數組
{
$tags[] = array('tagname'=>$rs->fields['tagname']->value);
$rs->MoveNext();
}
return $tags;
mysql_free_result($rs); //關閉資料集
}
為什麼我在php查詢mysql資料庫,操作記錄集時使用movenext方法一直報錯no-object?難道mysql記錄集不支援這個方法嗎,那該如何??另外迴圈裡的數組$tags在迴圈外能正確返回嗎?
我想將記錄集儲存到數組,並返回這個數組,請高手給看看!


回複討論(解決方案)

是的,不支援

while($row = mysql_fetch_assoc($rs))   //將記錄集儲存到二維數組{     $tags[] = $row;}

那return $tags;
這條語句能傳回值嗎?

當然能!
你遇到了什麼問題?

$tags只有一條記錄,很奇怪,如果查詢多個欄位,咋存到二維數組?儲存後效果$tags('tagname','device','unit'),能夠$tags[$i][tagname]這樣引用,這該咋存啊?mysql這塊和Oracle不太一樣,請幫幫忙,謝謝!
$sql = "select tagname,device,unit from TagList where device='$device'";
$rs = mysql_query($sql);
.......

奇怪了,經

while($row = mysql_fetch_assoc($rs))   //將記錄集儲存到二維數組{     $tags[] = $row;}

後 $tags 不就是二維數組了嗎?
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.