php dropdown,PHP下拉列表包含數據庫中的項目

I can't seem to get values of a table in my dropdownlist. I get no errors, only an empty dropdownlist. This is my code:

我似乎無法在我的下拉列表中獲取表的值。我沒有錯誤,只有一個空的下拉列表。這是我的代碼:

include_once ("classes/Keten.class.php");

$keten = new Keten();

$allKet = $keten->getAllKetens();

echo '';

while($row = mysql_fetch_array($allKet))

{

echo '' . $row['keten_naam'] . '';

}

echo '';

?>

Function getAllKetens works, because I use it in an other page.

函數getAllKetens有效,因為我在其他頁面中使用它。

Thanks in advance :)

提前致謝 :)

on request, the getAllKet() function in classes/Keten.class.php

根據要求,類/ Keten.class.php中的getAllKet()函數

public function getAllKetens()

{

include ("connection.php");

$sSql = "SELECT * FROM tblKetens;";

$vResult = mysqli_query($link, $sSql);

mysqli_close($link);

return($vResult);

}

6 个解决方案

#1

2

I'm not sure mixing mysqli and mysql commands can be done, in your fetch_array you used mysql_fetch_array instead of mysqli_fetch_array.

我不確定混合mysqli和mysql命令是否可以完成,在你的fetch_array中你使用mysql_fetch_array而不是mysqli_fetch_array。

#2

1

Your function getAllKetens() is closing the database. You shouldn't be trying to fetch a row after closing the connection to the database.

你的函數getAllKetens()正在關閉數據庫。在關閉與數據庫的連接后,您不應該嘗試獲取行。

Soap box aside: It might be nice to have some more standard naming convention going on in there, as well. If you're returning a handle to a mysql query object, consider $query or $hQuery instead of what's (to me) a lot more cryptic as $allKet. IMO, if a function is called "getAllKetens()" it should return an array of data, not a handle to a query.

除了肥皂盒:在那里進行一些更標准的命名約定可能會更好。如果你正在返回一個mysql查詢對象的句柄,那么考慮$ query或$ hQuery而不是(對我來說)更多的含義為$ allKet。 IMO,如果一個函數被稱為“getAllKetens()”,它應該返回一個數據數組,而不是一個查詢句柄。

#3

0

Make sure errors are turned on

確保錯誤已打開

View the source, If there are any errors, they will be hidden by the select tag

查看源,如果有任何錯誤,它們將被select標記隱藏

Do a print_r($allket); to see if getAllKeten() actually returned anything.

做一個print_r($ allket);看看getAllKeten()是否實際返回了任何內容。

#4

0

I suspect the $allKet is not what you think it is.

我懷疑$ allKet不是你想象的那樣。

First, check the HTML. If you are getting then

首先,檢查HTML。如果你得到那么

a) Check $allKet is a resouce (I think print_r will tell you). b) Check that the SQL is selecting rows. (try it in phpmyadmin) c) Check that you have correct spellings for field names.

a)檢查$ allKet是一個資源(我認為print_r會告訴你)。 b)檢查SQL是否正在選擇行。 (在phpmyadmin中嘗試)c)檢查字段名稱的拼寫是否正確。

If you are seeing entries, then

如果您看到條目,那么

a) Check the field names you are printing are correct b) Check you are not hiding them with an alias (the print will show the last field).

a)檢查打印的字段名稱是否正確b)檢查您是否使用別名隱藏它們(打印將顯示最后一個字段)。

Turn error reporting up (in php.inf) and remove any errors that are reported.

打開錯誤報告(在php.inf中)並刪除報告的任何錯誤。

#5

0

This part of your code looks fine:

這部分代碼看起來很好:

echo '';

while($row = mysql_fetch_array($allKet))

{

echo '' . $row['keten_naam'] . '';

}

echo '';

Your problem should lie in $allKet.

你的問題應該在$ allKet中。

Do you need to give Keten() any arguments to initialize anything?

你需要給Keten()任何參數來初始化任何東西嗎?

#6

0

Ok I got it

好,我知道了

use: while($row = mysqli_fetch_assoc($allKet))

use:while($ row = mysqli_fetch_assoc($ allKet))

instead of: while($row = mysql_fetch_array($allKet))

而不是:while($ row = mysql_fetch_array($ allKet))

Thank you all for your fast replies !

謝謝大家的快速回復!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值