Maverickb7 Posted February 28, 2006 Share Posted February 28, 2006 Hi, I was wondering if someone could point me in the right direction. I'm trying to have my mysql content listed on a single page in alphabetical with "A B C D E F ect.." at the top of the page. You click A and you'll get all items starting with A. Does anyone know of a tutorial I could use to learn how to do this? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/ Share on other sites More sharing options...
klitscher Posted February 28, 2006 Share Posted February 28, 2006 [!--quoteo(post=350165:date=Feb 28 2006, 12:52 AM:name=Maverickb7)--][div class=\'quotetop\']QUOTE(Maverickb7 @ Feb 28 2006, 12:52 AM) [snapback]350165[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi, I was wondering if someone could point me in the right direction. I'm trying to have my mysql content listed on a single page in alphabetical with "A B C D E F ect.." at the top of the page. You click A and you'll get all items starting with A. Does anyone know of a tutorial I could use to learn how to do this?[/quote]Try using the sql code: [code]SELECT *FROM `your_table`WHERE `name`LIKE 'a%'ORDER BY `name` ASC [/code]you could pass in a variable for the letter you would like to sort by from a link.so clicking on sort.php?letter=a would lead to: [code]$letter = $_GET['letter'];$sql = 'SELECT * ' . ' FROM `your_table` ' . ' WHERE `name` LIKE \'' . $letter . '%\'' . ' ORDER BY `name` ASC'; $result = mysql_query($sql);[/code]hope that helps Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-12965 Share on other sites More sharing options...
Maverickb7 Posted February 28, 2006 Author Share Posted February 28, 2006 Thanks for the help. I got it working great. :) Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-12969 Share on other sites More sharing options...
Maverickb7 Posted February 28, 2006 Author Share Posted February 28, 2006 I have one follow-up question if anyone could be so kind to answer it. Does anyone know what code I would use to have all items starting with numbers to be listed as #? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-12971 Share on other sites More sharing options...
Maverickb7 Posted March 1, 2006 Author Share Posted March 1, 2006 Anyone? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-13387 Share on other sites More sharing options...
Maverickb7 Posted March 3, 2006 Author Share Posted March 3, 2006 Still looking for help. Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-13994 Share on other sites More sharing options...
Maverickb7 Posted March 5, 2006 Author Share Posted March 5, 2006 Still no help? c'mon people :( lol I've been looking everywhere for a solution with no luck. :( Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-14431 Share on other sites More sharing options...
AndyB Posted March 5, 2006 Share Posted March 5, 2006 [code] $string = "whatever your string is ....";$first = {$string[0]};if ($first>0) { echo "#";}echo $string;?>[/code] Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-14434 Share on other sites More sharing options...
Sasuun Posted March 5, 2006 Share Posted March 5, 2006 perhaps you could use the function is_numeric()? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-14438 Share on other sites More sharing options...
Maverickb7 Posted April 7, 2007 Author Share Posted April 7, 2007 How would I do that? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-223562 Share on other sites More sharing options...
AndyB Posted April 7, 2007 Share Posted April 7, 2007 [quote author=Maverickb7 link=topic=87031.msg568630#msg568630 date=1175961957]How would I do that?[/quote]I bet the manual explains ... http://ca.php.net/manual/en/function.is-numeric.php Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-223567 Share on other sites More sharing options...
Maverickb7 Posted April 7, 2007 Author Share Posted April 7, 2007 Alright, I understand how it works and what it does. But could you point me in the right direction. I'm having trouble using # to display all numeric results. =( how would I use that with the sql line? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-223582 Share on other sites More sharing options...
Maverickb7 Posted April 7, 2007 Author Share Posted April 7, 2007 let's say I do what klitscher suggested and used his code. How would I tell the sql statement to grab all rows that start with a numeric vale? I want to type sort.php?letter=# and have it display all numeric results. Can anyone show me how to do this? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-223622 Share on other sites More sharing options...
Maverickb7 Posted April 7, 2007 Author Share Posted April 7, 2007 anyone? =( Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-223653 Share on other sites More sharing options...
Maverickb7 Posted April 7, 2007 Author Share Posted April 7, 2007 Well, I have to leave for a couple of hours so hopefully when I return someone was able to offer their help. I'm kinda stuck on this even though its a pretty simple task. If you could help I would be really grateful. Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-223797 Share on other sites More sharing options...
Maverickb7 Posted April 8, 2007 Author Share Posted April 8, 2007 It's been a few hours with no response. Does anyone know of another way to do what I want perhaps? Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-224000 Share on other sites More sharing options...
HaLo2FrEeEk Posted April 8, 2007 Share Posted April 8, 2007 I think you meant that you want all values with a number at the beginning to start with a # sign, so basically, 7teen would be listed as #7teen? Hmm...try this:[code]<?php$string = "7teen";$first = substr($string, 0, 1);if(is_numeric($first)) { $first = "#" . $first; $string = $first . substr($string, 1, strlen($string)); }echo $string;?>[/code]Hope this helps you out.edit: all you have to do is read in your array in a foreach loop like this (I use an example array):[code]<?php$string_arr = array("123", "teen", "7teen", "HaLo2FrEeEk", "Alex", "4lex");foreach($string_arr as $string) { $first = substr($string, 0, 1); // Gets the first character of the string if(is_numeric($first)) { // Checks to see if $first is a number $first = "#" . $first; // This would set $first to #7 $string = $first . substr($string, 1, strlen($string)); // This appends the last characters to the new $first; } echo $string . "<br />"; }?>[/code]This will output:#123teen#7teenHaLo2FrEeEkAlex#4lexSince your query results are sorted already, the order won't be a problem. Link to comment https://forums.phpfreaks.com/topic/3734-alphabetical-mysql-results/#findComment-224018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.