|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
Optimizing a MySQL Table with PHP
On my site I have it set that administrators can delete news articles. Unfortunetly when you delete a row in a MySQL it will jump to the next id in the table when you insert a new one. For example:
ID is auto increment date (timestamp) news(Blob) id | date | News 1 | 030603 |BLAHBLAHBLAH 2 | 030603 | BlahAgain If I delete the article 2 then insert another article It would have 1 | 030603 |BLAHBLAHBLAH 3 | 040603|AnotherBlah This creates a problem when displaying articles and editing articles. I know there is a way to optimize the tables. I can do it through PHPMyAdmin but if I don't know someone deleted an article I won't be able to optimize it. What I want is how you can optimize the table with php code. Is mysql_query("OPTIMIZE table') the proper way or is their some other code that youhave to do to optimize the table?
__________________
CHornJr "One day I'll know what I am doing" ![]() My Blog Suanhacky Lodge #49 Rebel Squadrons |
|
#2
|
|||
|
|||
|
The problem you are describing is not under the class of problems of Optimizing Table. However if your concern is just about the optimization tables, and if optimization serves your purpose, please find the following tool (its free) for table/database optimization.
http://www.webyog.com/ After installation find "Table Diagnostic..." under the "Tools" menu Thank You. |
|
#3
|
||||
|
||||
|
Then I must ask, how do I fix the problem I am describing.
|
|
#4
|
|||
|
|||
|
This shouldnt be a problem.
You should be using whatever number is in that unique field. to display articles you should just do a select and order them either from newest to oldest and display them, or better yet you should have a date field and order it by that. When you edit an article it hosuld have a way to display all the articles, and then click a link to edit. when you do that it should include that unique id so the eidt page knows what article you want to edit ie. http://mydomain.com/edit.php?article_id=2 |
|
#5
|
||||
|
||||
|
Here is the code on my edit page
PHP Code:
And in the option box it displays the latest article then a bunch of the deleted articles and then the rest of the articles. Here is a screenshot of it Right now my timestamp table is set to a size of 6 which records in the YYMMDD Format. WHat your suggesting I do is that I order by time stamp which would first require me to change the timestamp format, which isn't a big deal I don't see it fixing the problem cause as you can see in the options box it is displaying the dates of the deleted articles. Here is a screenshot of what is int he table(via MyPHPAdmin) |
|
#6
|
|||
|
|||
|
If the articles is deleted why is it still in the database.
Lets see your delete articles page, there has to be something wrong with that. |
|
#7
|
||||
|
||||
|
I deleted it witht he delete option in MyPHPAdmin. I didn't develop the delete page yet.
I deleted fromt heri cause I was trying something and that is when I learned of the problem. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Optimizing a MySQL Table with PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|