Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Index In A Mysql Database, Make the numbers follow
mrdee
post Apr 7 2008, 01:39 PM
Post #1


Super Member
*********

Group: [HOSTED]
Posts: 224
Joined: 18-July 07
From: Slough (UK)
Member No.: 46,682



I hope I am on topic here (It does have to do with web design, after all).

I have noticed that in a MySQL database, the 'id' field just keeps its numbers for every record, with the backdraw that, whenever you remove (a) record(s) from the table, you get your list numbered as eg. 1,5,6,7,12,25 etc.

This makes it a bit difficult of keeping track of the number of records in your table.
Is there a way of achieving (either in PHPMyAdmin or through the use of PHP) that the id field in your table gets sort of 'refreshed and updated' so you have a clearer view on the number of records in your database?

What I mean is, imagine the highest number in your 'id' field is 221, that does not necessarily mean you have 221 records in your table, as some records may have been removed.

So, if anyone can help, it would be very much appreciated.


Thanks in advance.
Go to the top of the page
 
+Quote Post
rvalkass
post Apr 7 2008, 02:10 PM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 1,920
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



There are other ways to tell how many rows there are in a database than changing all the IDs. The purpose of a unique ID is that it is unique (obviously) and permanent. Changing it can cause all sorts of problems with scripts.

If you go into phpMyAdmin and click on the database you want information for, then look at the list of tables in the middle, you will notice a column labeled Records. That is a count of how many rows are in each table.

If that doesn't take your fancy then try the following SQL:
SQL
SELECT COUNT(*) FROM `table_name` WHERE 1

That returns an integer, which is the number of rows in the table.

Changing all the IDs is never a good idea.
Go to the top of the page
 
+Quote Post
jlhaslip
post Apr 7 2008, 04:13 PM
Post #3


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

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



Changing the ID field of a Table element messes with the links between an element and those above/below it in the schema as Rvalkass suggests. Particularly if the ID is an index, which is often the case.
to re-new the ID numbers, you would need to read the table one row at a time and find all the rows 'connected' to it inside all the other tables above and below it with an eye toward changing the indexed values as you change the element's id field. Rather a complicated mess could result if you arbitrarily alter ID values.

Use the Count function to find out the number of rows as per rvalkass' suggestion.
Go to the top of the page
 
+Quote Post
mrdee
post Apr 7 2008, 06:49 PM
Post #4


Super Member
*********

Group: [HOSTED]
Posts: 224
Joined: 18-July 07
From: Slough (UK)
Member No.: 46,682



Thanks for your comments, gentlemen.
One more thing: is it possible to display that 'Record' field?
Ihave seen the SQL Query
CODE
SELECT COUNT(*) FROM `table_name` WHERE 1

rvalkass posted, but not 100% sure how to display that (probably using PHP).
You see, I have put a petition on my site, everything works perfectly and I display the result of the petition (bar the people's email addresses) on my site by using coding that was made with PHPRunner.(A program that generates PHP code to do things with a MySQL database, I used the 'printer friendly' page to display the list).

However, I would like to put something at the top such as "xxx people have already signed the petition" or to put a number (1,2,3,..... all nicely numerically ordered) next to every name, although the first solution might make more sense, ie.saying how many people signed, and have this automatically updated every time someone new signs.

As you can see, my knowledge of PHP is not yet strong enough, which is why I have to rely on programs like PHPRunner and the likes.

Anyway, thanks for your explanations you have sent in so far, and apologies for my ignorance.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Mysql Infos(2)
  2. Mysql Tool(0)
  3. Mysql And Ms Access(1)
  4. What If You Forget Mysql Root Password(2)
  5. Free Dhtml Menu That Reads A Database(7)
  6. Mysql Host Adress(4)
  7. Import From Excel File Into Mysql Database(5)
  8. Php And Mysql Problem(8)
  9. Tips On Creating Your Own Search(1)
  10. Syndicate Your Content Using Php And Mysql(0)
  11. Phpbb And Mysql Relations?(2)
  12. How Do You Combine Multiple Mysql Databases Into One Database?(3)
  13. Help Or Advise Needed For Access Database Webpage Conversions(0)
  14. Merging Database Php Mysql(5)
  15. Help With Database(24)
  1. Where Am I Going Wrong This Time?(4)
  2. Which Data Type To Use In Mysql Table(4)
  3. Another Question On Mysql Table Data Type(1)
  4. Accessing Mysql From Javascript(4)
  5. Mysql + Php Question(4)
  6. Treating .csv Files As Database Data(2)


 



- Lo-Fi Version Time is now: 16th May 2008 - 06:14 PM