php - mysql_fetch_array() 有一个奇怪的问题

标签 php mysql

为什么我无法进入 getCustomers() 函数中的 while 循环?

$stores = $bl->getStoresForGuide($gID);  //Returns 6 stores
$storelist = getStoreList($stores);      //Generate the HTML for the store list
$brandlist = getCustomers($stores);      //Generate the HTML for brand list

function getStoreList($stores) 
{
  while ($row = mysql_fetch_array($stores)) {
    // Do stuff 
  }
 //return result
}


function getCustomers($stores)
{
  echo mysql_num_rows($stores);  //Outputs 6

  while ($row = mysql_fetch_array($stores)) {
    echo "test "; // Outputs nothing
  }
  // Return some result
}

最佳答案

你循环了两次。第一次循环时,您会到达终点,并且在您再次循环之前不会重置指针。

如果您确定要执行此操作,请查看 mysql_data_seek , 并寻找结果的开头。否则,我建议只存储结果并遍历数组。

关于php - mysql_fetch_array() 有一个奇怪的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2136863/

相关文章:

php - 使用 MySQL 和 PHP 的 SQL 语法错误

php - 如何使用存储过程的字符串 id 插入多条记录?

php - 避免 PHP 中重复的 ID

php - 带引号的姓氏会破坏 SQL 查询,如何解决?

php - 使用 PDO 语句未将数据插入 mysql

MySQL选择特定数量并计算所有可能

php - 扩展 DOMDocument 和 DOMNode : problem with return object

php - 用php启动ffmpeg转码

php - 随机数据的 MD5 散列列表不统一 (PHP)

mysql - 如何对 MySQL 数据库表执行此查询?