View Full Version : mysql ordering problem
wbarrett26
June 9th, 2005, 12:11 PM
I have a question hopefully someone can help with.
I have several mysql tables setup with an "id" used as the primary, self incrementing value. After delteting some entries the table goes out of order, for example one table with 60+ entries I deleted id 1, and now the order is 3,2,4 in the beginning. and tables with over 100 entries have an order like 18,19,108,21. is there anyway to fix this or am I stuck with the problem? My main objective is to make it so that when a table is exported to an excel table the id's are in order. Thanks for any insight.
JustJeff
June 9th, 2005, 05:45 PM
First, backup your data. Then, you may consider trying this to reorder the table:
ALTER TABLE `tableName` ORDER BY `id`
Please don't try this without reading the documentation. As with any code you find on a forum, it may DAMAGE your data (if I made a typo, if I'm dumb, etc) - use at your own risk.
JustJeff
June 9th, 2005, 05:45 PM
First, backup your data. Then, you may consider trying this to reorder the table:
ALTER TABLE `tableName` ORDER BY `id`
Please don't try this without reading the documentation. As with any code you find on a forum, it may DAMAGE your data (if I made a typo, if I'm dumb, etc) - use at your own risk.
wbarrett26
June 10th, 2005, 09:02 AM
Thanks Jeff,
I am still learning all the aspects of MySQL. But I know realize that this was an including function in phpMyAdmin. Thanks for the info it worked perfect
teiz77
June 10th, 2005, 09:54 AM
the ordering in the database is not really important. Don't worry about that. You should include an "ORDER BY <columname>" in your "SELECT" statement to order the results of a query.
wbarrett26
June 10th, 2005, 11:24 AM
just to make sure i do it right should my current code:
$select = "SELECT * FROM table bills0605";
$export = mysql_query("SELECT * FROM bills0605",$connection);
$fields = mysql_num_fields($export);
should be switched to something like this:
$select = "SELECT * FROM table bills0605 ORDER BY id";
$export = mysql_query("SELECT * FROM bills0605",$connection);
$fields = mysql_num_fields($export);
teiz77
June 10th, 2005, 11:37 AM
just to make sure i do it right should my current code:
$select = "SELECT * FROM table bills0605";
$export = mysql_query("SELECT * FROM bills0605",$connection);
$fields = mysql_num_fields($export);
should be switched to something like this:
$select = "SELECT * FROM table bills0605 ORDER BY id";
$export = mysql_query("SELECT * FROM bills0605",$connection);
$fields = mysql_num_fields($export);
in the above code the $select query isn't performed... do you call it later on? The query itself is correct.
four1seven
June 10th, 2005, 01:33 PM
$select = "SELECT * FROM table bills0605 ORDER BY id";
$export = mysql_query($select,$connection);
$fields = mysql_num_fields($export);
call the $select variable instead of typing in the SELECT query again.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.