Jump to content

Order By (exclude Numbers Untill Letters Checked)


morrisjohnny

Recommended Posts

Hello, I've got a query working

$gmenu=mysql_query("SELECT * FROM products GROUP BY cat ORDER BY cat");while($smenu=mysql_fetch_array($gmenu)){	echo'<div style="background-color:#999999;border:#000000 thin solid;width:100%;">'.stripslashes($smenu["cat"]).'</div>		<div style="background-color:#CCCCCC;width:100%;border:#000000 thin solid;" id="'.$smenu["Name"].'">';	$g=mysql_query("SELECT * FROM products WHERE cat='{$smenu['cat']}' GROUP BY size ORDER BY size");	while($s=mysql_fetch_array($g))	{		echo'-<a style="width:100px;color:#666666;" href="Products.php?cat='.$s["cat"].'&Size='.$s["size"].'">'.$s["size"].'</a><br />';	}	echo'</div>';}}

okay i'm aware changing line 10 to thisg=mysql_query("SELECT * FROM products WHERE cat='{$smenu['cat']}' GROUP BY size ORDER BY size LIKE '%E'");will order the data so the values are in D,E categories but not numerical aswell.Now, cat has values such as 32D 34D and 32E and 34E obioulsy it gets sorted like 32D,32E,32D then 34Enow what i'm waiting it to keep all the D's together then E's together so it would show up like this 32D,34D, 32E and then 34Enow i know very little about SQL and was wonder if their was an option to search by the final letter then any letters or search once for letters then order by that and then order again by the full value.however please note their may be more than one letter at the end for example it might be DD or DE or even CD etc.I'm doing this in PHP if anyone wants to help. i can make while statements etc. but it's the SQL part i'm not understanding.ThanksJny

Link to comment
Share on other sites

Now, cat has values such as 32D 34D and 32E
Exactly what kind of website are you running here, pal? If you're selling bras for strangely-proportioned women, I'm going to need to see some examples.If all of them have 2 digits before the letters, you could use a string function like substr to order by the letters. e.g.:ORDER BY SUBSTRING(cat, 3), cator:ORDER BY RIGHT(cat, 1), SUBSTRING(cat, 3), cathttp://dev.mysql.com/doc/refman/5.0/en/string-functions.html
Link to comment
Share on other sites

Thanks again JustSomeGuy.It's for a familty member who is infact selling Bra's etc.here's a testing link we are currently working onHttp://alantest.freehostia.com/Thanks once again for your help, in the end the final result was to create a sub category.i'm currently int he process of ironing out the creases before i shoot of to uni on Sunday to study internet computing. Thanks JustSomeGuy :)-Jny

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...