Low cost ecommerce web development India flash website design

Counting Rows with PHP


With PHP, the function mysql_num_rows returns the number of rows selected,
but its application can be limited when you use unbuffered queries (see “How
[1] http://pear.php.net/package-info.php?package=DB_DataObject

How do I find out how many rows I've selected? do I fetch data from a table?"). The following code illustrates the use of mysql_num_rows: File: 12.php (excerpt) // A query to select all articles $sql = "SELECT * FROM articles ORDER BY title"; // Run the query, identifying the connection $queryResource = mysql_query($sql, $dbConn); // Fetch the number of rows selected $numRows = mysql_num_rows($queryResource); echo $numRows . ' rows selected
'; // Fetch rows from MySQL one at a time while ($row = mysql_fetch_array($queryResource, MYSQL_ASSOC)) { echo 'Title: ' . $row['title'] . '
'; echo 'Author: ' . $row['author'] . '
'; echo 'Body: ' . $row['body'] . '
'; } The mysql_num_rows function, demonstrated in the above example, takes a result set resource identifier and returns the number of rows in that result set. Note that the related function, mysql_num_fields, can be used to find out how many columns were selected. This can be handy when you're using queries like SELECT * FROM table, but you don't know how many columns you've selected.

website designer freelance ASP PHP ecommerce web developer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110