Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource


juliusyves

Recommended Posts

Here are my OOP methods from different classes, late static binding is implemented. Kindly help me implement mysql_num_rows. Thanks guys

 

 

public function num_rows($result_set) {

return mysql_num_rows($result_set);

}

 

public function query($sql) {

$this->last_query = $sql;

$result = mysql_query($sql, $this->connection);

$this->confirm_query($result);

return $result;

}

 

public static function find_all() {

return static::find_by_sql("SELECT * FROM ".static::$table_name);

}

 

  public static function find_by_sql($sql="") {

    global $database;

    $result_set = $database->query($sql);

$object_array = array();

while ($row = $database->fetch_array($result_set)) {

$object_array[] = static::instantiate($row);

}

return $object_array;

  }

 

  private static function instantiate($record) {

  $class_name = get_called_class();

  $object = new $class_name;

 

foreach($record as $attribute=>$value){

if($object->has_attribute($attribute)) {

$object->$attribute = $value;

}

}

return $object;

  }

 

 

<?php

  // Find all the car

$car_set = Car::find_all();

$car_count = $database->num_rows($car_set);

echo $car_count;

?>

Link to comment
Share on other sites

You're not passing it a resource, you're passing it an array.

 

I suggest that you persist the $result_set resource from your query function, and eliminate the parameter requirement in num_rows(), having it use the persisted resource instead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.