alko123 Posted February 2, 2007 Share Posted February 2, 2007 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 More sharing options...
Cep Posted February 2, 2007 Share Posted February 2, 2007 What exactly are we testing for? The reason your most likely to get 0 is because there are no records in your table. Link to comment https://forums.phpfreaks.com/topic/36759-mysql_num_rows-still-give-me-a-zero/#findComment-175325 Share on other sites More sharing options...
alko123 Posted February 3, 2007 Author Share Posted February 3, 2007 i have in the table 21 records. so ,i think that the mysql_num_rows should give me a 21, not 0. its that right? and there is the problem. this script gives me always zero. Link to comment https://forums.phpfreaks.com/topic/36759-mysql_num_rows-still-give-me-a-zero/#findComment-176017 Share on other sites More sharing options...
sayedsohail Posted February 3, 2007 Share Posted February 3, 2007 I think try innerjoin or left join in your sql syntax, this should solve your problem. Link to comment https://forums.phpfreaks.com/topic/36759-mysql_num_rows-still-give-me-a-zero/#findComment-176021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.