Low cost ecommerce web development India flash website design
The alternative approach is to use MySQL’s COUNT function within the query.
This requires that you perform two queries—one to count the results and
one to
actually get the results—which will cost you a little in terms of performance.
Here’s how you could use the MySQL COUNT function:
File: 13.php (excerpt)
// A query to select all articles
$sql = "SELECT COUNT(*) AS numrows FROM articles";
// Query to count the rows returned
$queryResource = mysql_query($sql, $dbConn);
Chapter 3: PHP and MySQL
Counting Rows with MySQL
$sql = "SELECT COUNT(*) as numrows" . $table . $where;
// Run the query, identifying the connection
$queryResource = mysql_query($sql, $dbConn);
$row = mysql_fetch_array($queryResource, MYSQL_ASSOC);
echo $row['numrows'] . " rows selected<br />";
// A query to fetch the rows
$sql = "SELECT * " . $table . $where . $order;
// Run the query, identifying the connection
$queryResource = mysql_query($sql, $dbConn);
// Fetch rows from MySQL one at a time
while ($row = mysql_fetch_array($queryResource, MYSQL_ASSOC)) {
echo 'Title: ' . $row['title'] . '<br />';
echo 'Author: ' . $row['author'] . '<br />';
echo 'Body: ' . $row['body'] . '<br />';
}
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