Jump to content

mysql_num_rows still give me a zero


alko123

Recommended Posts

Hi

can you please test this code

its from book About PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide from Larry Ulman

 

 

 

// Connect to the database.

$db_connection = mysql_connect ('localhost', 'root', '') or die (mysql_error());

$db_select = mysql_select_db('larrys_books') or die (mysql_error());

 

// If we don't know how many pages there are, make that calculation.

if (!isset($num_pages)) {

 

  // Determine the query.

  if ($letter) { // Browsing a particular letter or the whole shebang?

    $query1 = "SELECT books.title, books.author_id, CONCAT(authors.first_name, ' ', authors.last_name) AS author, formats.format FROM books, authors, formats WHERE authors.author_id = books.author_id AND formats.format_id = books.format_id AND title LIKE '$letter%' ORDER BY title ASC";

  } else {

    $query1 = "SELECT books.title, books.author_id, CONCAT(authors.first_name, ' ', authors.last_name) AS author, formats.format FROM books, authors, formats WHERE authors.author_id = books.author_id AND formats.format_id = books.format_id ORDER BY title ASC";

  }

 

  // Query the database.

  $query_result1 = @mysql_query ($query1) or die (mysql_error());

 

  // Calculate the number of pages required.

  $num_results = mysql_num_rows ($query_result1);

  if ($num_results > $display_number) {

    $num_pages = ceil ($num_results/$display_number);

  } elseif ($num_results > 0) {

    $num_pages = 1;

  } else {

    echo 'There are no books in this category.';

    echo $num_results;

  }

 

Link to comment
https://forums.phpfreaks.com/topic/36759-mysql_num_rows-still-give-me-a-zero/
Share on other sites

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.