SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: How to count table record
-
Oct 18, 2007, 00:19 #1
- Join Date
- Aug 2007
- Posts
- 256
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How to count table record
Hey.guys! I have a table here and would like to display all records.How could I count the number of record in table without manually specifying it in query statement.
Code:$result =mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s LIMIT 7', $tbl_name));
-
Oct 18, 2007, 00:32 #2
- Join Date
- Aug 2007
- Posts
- 256
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I tried the following script,it can't work
Code:$tbl_name = "movie"; $query = mysql_query("SELECT * FROM $tbl_name"); $num_row = mysql_num_rows($query); $result = mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s LIMIT $num_row', $tbl_name)) or die('Cannot execute query.');
-
Oct 18, 2007, 04:45 #3
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
-
Oct 18, 2007, 06:10 #4
- Join Date
- Aug 2007
- Posts
- 256
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I can't perform query in the script,what went wrong on it?
Code:$tbl_name = "movie"; $num_row = mysql_result(mysql_query("SELECT COUNT(DISTINCT name)FROM $tbl_name"),0); $result = mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s LIMIT "$num_row"', $tbl_name)) or die('Cannot execute query.');
-
Oct 18, 2007, 06:18 #5
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
no idea
moving thread to php forum
-
Oct 18, 2007, 06:31 #6
If you want to display all the records, there is no need to count them first and then use LIMIT.
Just select them all:
PHP Code:$result = mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s', $tbl_name)) or die('Cannot execute query.');
Guido - Community Team Leader
The Votes Are In: The Winners of the 2013 Community Awards are...
Blog - Free Flash Slideshow Widget
Bookmarks