Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Showing Numbers Of Mysql Entries In A Database Table, It should be easy, but I don't know how...
Amezis
post May 9 2006, 03:10 PM
Post #1


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



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? smile.gif
Go to the top of the page
 
+Quote Post
jlhaslip
post May 9 2006, 03:36 PM
Post #2


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,753
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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

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.

Go to the top of the page
 
+Quote Post
farsiscript
post May 9 2006, 03:41 PM
Post #3


Super Member
*********

Group: Members
Posts: 357
Joined: 8-April 06
Member No.: 21,487



plz help me
1- How can i count how many raws is one table ?
2 - i want update one raw , how can user update Query Command
3 - How can make one Tabel or Delete one tabel with raws
thanks

This post has been edited by farsiscript: May 9 2006, 03:44 PM
Go to the top of the page
 
+Quote Post
jlhaslip
post May 9 2006, 04:02 PM
Post #4


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,753
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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:
CODE

UPDATE 'table_name' SET email='$variable_name' WHERE table_index = xx LIMIT 1;
Go to the top of the page
 
+Quote Post
Amezis
post May 9 2006, 06:37 PM
Post #5


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



QUOTE(jlhaslip @ May 9 2006, 05:36 PM) *

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

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:

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


This post has been edited by Amezis: May 9 2006, 06:49 PM
Go to the top of the page
 
+Quote Post
kl223
post May 9 2006, 07:17 PM
Post #6


Newbie
*

Group: Members
Posts: 5
Joined: 8-May 06
Member No.: 23,256



Hi!

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

http://dev.mysql.com/doc/ => MySQL documentation with SQL syntax reference.
http://sqlcourse.com/ and http://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://www.php.net/manual/en/ => PHP searchable reference. All the functions are there, so it's a "must have" for php programmers.


QUOTE(Amezis @ May 9 2006, 08:37 PM) *

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

CODE
<?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://hu2.php.net/manual/en/function.mysql-query.php

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

This post has been edited by kl223: May 9 2006, 07:18 PM
Go to the top of the page
 
+Quote Post
Amezis
post May 9 2006, 07:26 PM
Post #7


Privileged Member
*********

Group: Members
Posts: 535
Joined: 14-February 05
From: Oslo, Norway
Member No.: 3,759



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 smile.gif
Go to the top of the page
 
+Quote Post
Spectre
post May 10 2006, 02:09 AM
Post #8


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



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

CODE
$result = mysql_query('SELECT COUNT(*) FROM table_name');
$array = mysql_fetch_array($result);
echo $array[0];
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Problem On Mysql "order By"(5)
  2. Increment A Mysql Column(6)
  3. Can You Add Images Into A Mysql Database?(20)
  4. Creating Profiles In Php/mysql ?(7)
  5. Php Search Engine Script For Mysql Database(11)
  6. Simple Mysql Query Limiting(9)
  7. Phpbb2 Error(4)
  8. Some Mysql Basics(4)
  9. Php, Mysql, Apache(4)
  10. Auto Pruning An Sql Database With Php(4)
  11. Php And Mysql Applications(3)
  12. Blank/duplicate Entries(5)
  13. Getting Php 5 To Work With Mysql(0)
  14. Problem With A Mysql Join(2)
  15. Can Database Column Names Start With A Number?(1)
  1. The Artists Tutorials :mysql Basic Commands(0)
  2. Connecting Php Site To Database(6)
  3. [mysql]get Id Of Loged In User?(7)
  4. [mysql/php]need Som Basic Help(13)
  5. [php/mysql]id Trouble [resolved](3)
  6. Mysql Won't Update(2)
  7. Php + Mysql Question!(4)
  8. Tools Needed!(6)
  9. Best Sites For Learning Php-mysql(4)
  10. How Do I Connect To Live Database With Php Script?(6)