Jump to content

[SOLVED] function problem


darkfreaks

Recommended Posts

mysql_fetch_array not a valid MYSQL resource on line 7

 

 

code:

 

<?php
function fetch($query)
{
include "config.inc.php";
$result=mysql_query($query);
 while ($row = mysql_fetch_array($result)) {//line 7
          $return = $row;
    }
    return $return;
}><

Link to comment
https://forums.phpfreaks.com/topic/138830-solved-function-problem/
Share on other sites

Indeed it does. And because you have absolutely no error handling in place you get an ugly error.

 

<?php
function fetch($query) {
  include "config.inc.php";
  if ($result = mysql_query($query)) {
    if (mysql_num_rows($result) == 1) {
      return mysql_fetch_assoc($result);
    } else if (mysql_num_rows($result) > 1) {
      while ($row = mysql_fetch_assoc($result)) {
        $return[] = $row;
      }
      return $return;
    }
    return false;
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.