HOW TO TRACK MYSQL DATABASE STATISTICS?

Hello,

I am new to mysql and would like to know if this is possible:

I want to for example:

Track how many columns within my table have been created
& Track the last one created

For like to embed in a page in order to view it daily (updates automatically of course).

any idea??

Hi there,

Just to confirm, do you definitely mean columns? Or do you mean each entry in a database table i.e. a row (columns = vertical, rows = horizontal).

each entry in a database table

I don’t know how you’re connecting to your mysql database, but ive included the basics as if you had the defaults from installing XAMPP.

<?php
$db = mysql_connect("localhost","root");
mysql_select_db("my_database");
$entries = array();
$sql = "SELECT
			`field`
		FROM
			`tablename`
		ORDER BY
			`id` DESC
		LIMIT 10";
$query = mysql_query($sql);
while(($row = mysql_fetch_assoc($query)) !== false)
{
	$entries[] = $row['field'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title></title>
    </head>
    <body>
		<p>
			Last 10 entries (most recent at the top):
		</p>
		<ul>
        <?php
		foreach($entries as $entry)
		{
			echo "<li>".$entry."</li>";
		}
        ?>
		</ul>
    </body>
</html>

Of course you will need to modify this depending on what limit you want (if any), your database connection, table name, field name etc but let me know if this helps you at all.

yes !! thnx!

I used include “connection.php”; to connect … its easier

No problem - glad to have helped. Happy coding and a prosperous new year :smiley:

what if I only want to show 1 instead of 10?

Where it says “LIMIT 10” at the end of the query, simply change the 10 to a 1.

yes ty I found out right away… thnx for everything and happy new year

Sponsor our Newsletter | Privacy Policy | Terms of Service