Jump to content
xisto Community
Sign in to follow this  
Amezis

Showing Numbers Of Mysql Entries In A Database Table It should be easy, but I dont know how...

Recommended Posts

I have a database, and need to know how to show the numbers of entries. So, if there are 10 entries in the selected database table, it will show the number 10. I'm pretty sure this should be easy, but I don't know how to do it. Can someone tell me? <_<

Share this post


Link to post
Share on other sites

SQL Query to find out the number of items in this Table would be something like:

SELECT COUNT(*) FROM 'test_table';

Assuming you have opened the DB and made a connection properly. This is not the php code, just the mysql select to count the number of items in a table.

Post back here if you need the php, too.

Share this post


Link to post
Share on other sites

Your first question is answered in the above posting.

The answer to the second question is to have a page or link which:
SELECT(s) the DB entry you want to edit,
displays to the user the specific SELECT(ed) information for editting which you currently have in the DB,
allows the user to make the changes,
accepts the form when the submit button is clicked,
validates the information against the range of acceptable values,
performs security measures (ie: stripslashes, htmlentities, etc) against the input,
then writes a query to update the row (either partial or full row) of information back into the DB.

Again, I assume that you have opened a DB connection properly, built a form, etc. I am not at my usual computer or I could post a complete sample, but the psuedo-code above may help you understand the process.

A sample of the SQL statement to update a single partial row would be:

UPDATE 'table_name' SET email='$variable_name' WHERE table_index = xx LIMIT 1;

Share this post


Link to post
Share on other sites

SQL Query to find out the number of items in this Table would be something like:

SELECT COUNT(*) FROM 'test_table';

Assuming you have opened the DB and made a connection properly. This is not the php code, just the mysql select to count the number of items in a table.

Post back here if you need the php, too.
Thanks! But how can I echo that number? I tried this, but it doesn't work:

<?php echo mysql_query("SELECT COUNT(*) FROM 'table_name'"); ?>

Edited by Amezis (see edit history)

Share this post


Link to post
Share on other sites

Hi!

As usual, I want to show you all some links from my collection. :)
These should be useful in the future.

http://dev.mysql.com/doc/ => MySQL documentation with SQL syntax reference.
http://www.sqlcourse.com/ and http://www.sqlcourse2.com/ => both are interactive, free SQL tutorial sites. I learned SQL there, there is an SQL interpreter on the site for practice, etc.
http://php.net/manual/en/ => PHP searchable reference. All the functions are there, so it's a "must have" for php programmers.


Thanks! But how can I echo that number? I tried this, but it doesn't work:

<?php echo mysql_query("SELECT COUNT(*) FROM 'table_name'"); ?>

It is because the mysql_query function does not return the result of the query.
http://forums.xisto.com/no_longer_exists/

Instead of the result it returns a special resultset which contains all the results. See the manual (mysql_fetch_array, etc).
I suggest, you should build up an own environment. (Basically, a wrapper for the php library functions. It should be in OOP. For example you should develop a MySQLConn class, which manages a mysql connection and with the methods it can be controlled.)

That way, you can reuse the code in later applications, too. You don't have to rewrite it.

kl223
Edited by kl223 (see edit history)

Share this post


Link to post
Share on other sites

Well, thanks, but I'd rather learn something when I need it. At the moment, I only need to know how to echo the results, not how to use MySQL in general. If anyone could simply help me directly, or tell me how to do it (and not tell me what I should NOT do), I would really appreciate it :)

Share this post


Link to post
Share on other sites

I would recommend you learn how to do it rather than simply have someone show you. All the same, here is a quick example:

$result = mysql_query('SELECT COUNT(*) FROM table_name');$array = mysql_fetch_array($result);echo $array[0];

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.