Total Database Records
#1
Posted 18 March 2008 - 06:12 PM
Such as "TOTAL DATABASE RECORDS: *INSERT NUMBER*" kinda thing.
So does anybody have any idea what code will do that? Any help would be much appreciated!
#2
Posted 18 March 2008 - 06:19 PM
A simple mysql query:
SHOW TABLES
Will return to you a list of table names, loop through the result set and take a count off all the rows.
I am sure you can work the code out as it is nice and easy
Matt
Edited by Mr. Matt, 18 March 2008 - 06:19 PM.
#3
Posted 18 March 2008 - 06:28 PM
'preciate it.
#4
Posted 19 March 2008 - 09:35 AM
In my previous post I have pretty much said how to do it in psudo form, just read that a few times and work out which functions you need.
Like I said it is pretty simple and is no more then 10 lines of code, you can do it
Matt
#5
Posted 19 March 2008 - 12:08 PM
http://dev.mysql.com...how-tables.html
#6
Posted 19 March 2008 - 12:29 PM
Seriously - the basics are as much as I've ever needed to use. The SELECT function is the only SQL I've ever used.
$sql_query = mysql_query("show tables"); $totalrows = mysql_num_rows($sql_query); print "<b><u>Total Database Entries:</u></b><br>"; print "$totalrows<br><br>";
That's what I've used - however that is only printing "5" when there are 5 tables and 6 records. I know what I've done wrong, I just don't know how to fix it.
As for the learning thing - I'm weird in that I learn by reading other people's code and then seeing what it does - somehow that flicks a light switch in my head. MySQL is not something I know, PHP I barely know and I certainly don't know how to mix the two.
Edited by ian mullen, 19 March 2008 - 12:32 PM.
#7
Posted 19 March 2008 - 12:32 PM
#8
Posted 19 March 2008 - 12:59 PM
mysql_num_rows($sql_query);
This bit is finding the number of tables, rather than the number of rows in the tables. That's where I've gone wrong. I think anyway. Maybe that line is needed, but I need to do something else first? I dunno what though.
#9
Posted 19 March 2008 - 02:32 PM
#10
Posted 19 March 2008 - 03:07 PM
$sql_query = mysql_query("show tables"); print "$sql_query";
Produces the following, not a list of tables:
"Resource id #5"
Seriously dude I don't think I'm gonna get this - I've tried everything I can think of.
#11
Posted 19 March 2008 - 03:17 PM
Try either print_r or do a while loop like:
while($tbl = mysql_fetch_array($query))
{
echo $tbl[0]
}
#12
Posted 19 March 2008 - 03:18 PM
#13
Posted 19 March 2008 - 03:24 PM
#14
Posted 19 March 2008 - 03:38 PM
But did it work for you now?
#15
Posted 19 March 2008 - 03:39 PM
#16
Posted 19 March 2008 - 04:03 PM
Yes I'm getting frustrated. This problem is starting to really annoy me and I'm getting no help from anyone.
Will someone please just give me a sample of the code I want. I'll learn from that! That's how I've learned everything I know so far - tutorials and other people's coding.
Edited by ian mullen, 19 March 2008 - 04:04 PM.
#17
Posted 19 March 2008 - 04:22 PM
$query= mysql_query("SHOW TABLE STATUS"); while($tbl = mysql_fetch_array($query)) { echo $tbl[Rows]."<br>"; }
that prints out the number of rows in each table. Basically, create a veriable outside the while loop. Then in the while loop, add the number to the veriable outside.
Edit:
Also, i was just looking around the php manual and i found this:mysql_stat()
http://www.php.net/m....mysql-stat.php
Not too sure if it helps but it could
Edited by BigDog, 19 March 2008 - 04:33 PM.
#18
Posted 19 March 2008 - 04:33 PM
That displays the number of rows in each table perfectly. Still a numbnuts here though - how do I create a variable outside the while loop and what would it look like?
I'm sorry I got annoyed - but it really started to frustrate me when nothing worked.
#19
Posted 19 March 2008 - 04:35 PM
$mycount = 0; while(XXXXX) { $mycount .= $tbl[XXX]; }
I think that shoul do.
#20
Posted 19 March 2008 - 04:42 PM
2bh, I don't even know what to put in place of the Xs...
Yes, I do feel quite stupid now but hey - as long as it all works in the end, I'll be happy.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users