supplied argument is not a valid MySQL result
I have written a function:
function selectWithPaging($where){
 $pg = (int) (!isset($_GET["pg"]) ? 1 : $_GET["pg"]);
 $pg = ($pg == 0 ? 1 : $pg);
 $perpage = 10;//limit in each page
 $startpoint = ($pg * $perpage) - $perpage;
 $result = mysql_query("SELECT * FROM $where ORDER BY id ASC LIMIT $startpoint,$perpage");
 return $result;
               }
but when inserting in this function :
function categories() { 
 selectWithPaging('category') 
 $text .='<h2 class="mainH">Categories</h2>';
 $text .= '<table><tr class="cn"><td>ID</td><td class="name">Category</td>  <td>Durum</td>'; 
 while ($row = mysql_fetch_array($result)) {
 $home    = $row['home']; 
 $publish = $row['published'];
 $ID = $row['id'];
 $src = '<img src="'.ADMIN_IMG.'homec.png"开发者_如何学C>';
                      -------------
          }
there is this error: supplied argument is not a valid MySQL result
What is wrong in my first function?
This may be a typo, but your first function returns a result that isn't being caught by any variable in your second function.
change:
selectWithPaging('category')  
to:
$result = selectWithPaging('category');  
and give it a try.
Your query isn't running.  It's either because you haven't passed the $dblink arg to mysql_query, or because your SQL syntax has an error.  This should tell you what's happening.
$dblink=mysql_connect('localhost', 'mysql_user', 'mysql_password');
try{
  $query="SELECT * FROM $where ORDER BY id ASC LIMIT $startpoint, $perpage";
  $result = mysql_query($query,$dblink) or throw new Exception(mysql_error($dblink));
  return $result; 
} catch(Exception $e){
    echo $e->getMessage();
} 
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论