|
|
|
|
![]() ![]() |
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?
|
|
|
|
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: [MODERATOR] Posts: 3,753 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
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. |
|
|
|
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 |
|
|
|
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: [MODERATOR] Posts: 3,753 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
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; |
|
|
|
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 |
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 |
|
|
|
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. 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. 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 |
|
|
|
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
|
|
|
|
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]; |
|
|
|
![]() ![]() |
Similar Topics