Jump to content


Photo

sorting by columns not working??


  • Please log in to reply
3 replies to this topic

#1 rhock_95

rhock_95
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 18 August 2003 - 06:42 PM

hope someone can help me... I have a table (see below) that ai am adding data to OUT side of chronological order...(i.e., categorically by alphabetical order...).... this puts the \"ID\" (auto increment) out of sync alphabetically...

My problem when I go back and reset the table order by \"category\"... it is not correct... there will be blocks of \"A\'s\" , \"B\'s\" , \"c\'s\", then more :A\'s\" etc... etc..


can anyone help me?

CREATE TABLE `bus_list` (
`name` varchar(255) NOT NULL default \'\',
`address` varchar(255) NOT NULL default \'\',
`city` varchar(255) NOT NULL default \'\',
`zip` varchar(15) default NULL,
`phone` varchar(40) default NULL,
`www` varchar(255) default NULL,
`notes` text,
`cat` varchar(255) default NULL,
`id` int(11) unsigned NOT NULL auto_increment,
`subcatid` varchar(11) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 August 2003 - 06:59 PM

Have you tried

[php:1:dc6dc8338d]<?php
$sql = \"SELECT * FROM bus_list ORDER BY cat\";
?>[/php:1:dc6dc8338d]

there will be blocks of \"A\'s\" , \"B\'s\" , \"c\'s\", then more :A\'s\" etc... etc..


Is that \":A\" actually one of your categories or is it a typo?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 rhock_95

rhock_95
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 18 August 2003 - 08:15 PM

by \"A\" I meant several categories that begin with the letter \"A\"...

the problem is... I have a script that has two drop down menus that are populated by the database... on is \"Citiy\" and the other is \"category\"

I really need the category menu to be in exact alphabetical order...?

any ideas?


//get data for city and category
$sql = \'SELECT DISTINCT city FROM bus_list\';
$r = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($r))
{
$city[] = $row->city;
}

$sql = \'SELECT DISTINCT category FROM bus_list\';
$r = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($r))
{
$category[] = $row->category;
}

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 August 2003 - 06:58 PM

As I said in my last post

..... ORDER BY cat
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users