Pmzine Posted May 24, 2006 Share Posted May 24, 2006 Hey,Hopefully a quick and easy question, I have a MYSQL database with reviews in it and an A-Z archive. For instance, if you click 'A' link it will show all reviews beginning with the letter 'A'.I want to be able to grab the reviews beginning with a numeric value though and can't figure out the character to pass to the SQL statement.Any ideas? Link to comment https://forums.phpfreaks.com/topic/10362-selecting-columns-beginning-with-a-numeric-character/ Share on other sites More sharing options...
urbandsigns.com Posted May 24, 2006 Share Posted May 24, 2006 [!--quoteo(post=376726:date=May 24 2006, 11:31 AM:name=Pmzine)--][div class=\'quotetop\']QUOTE(Pmzine @ May 24 2006, 11:31 AM) [snapback]376726[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hey,Hopefully a quick and easy question, I have a MYSQL database with reviews in it and an A-Z archive. For instance, if you click 'A' link it will show all reviews beginning with the letter 'A'.I want to be able to grab the reviews beginning with a numeric value though and can't figure out the character to pass to the SQL statement.Any ideas?[/quote]Pass in a # sign and then do an If statement for each number. Link to comment https://forums.phpfreaks.com/topic/10362-selecting-columns-beginning-with-a-numeric-character/#findComment-38636 Share on other sites More sharing options...
Barand Posted May 24, 2006 Share Posted May 24, 2006 [code].... WHERE SUBSTRING(review, 1,1) IN ('0','1','2','3','4','5','6','7','8','9')[/code] Link to comment https://forums.phpfreaks.com/topic/10362-selecting-columns-beginning-with-a-numeric-character/#findComment-38729 Share on other sites More sharing options...
Pmzine Posted May 26, 2006 Author Share Posted May 26, 2006 This is the SQL statement I'm using so far:[code]$sql = "select * from cdreviews ";if ($_GET['sort_by']) { $letter = $_GET['sort_by']; $sql .= "where name like '".$letter."%' ORDER BY name ASC";} else { $sql .= "order by dateadded DESC limit 10";}[/code]How would I integrate that statement into it? Link to comment https://forums.phpfreaks.com/topic/10362-selecting-columns-beginning-with-a-numeric-character/#findComment-39238 Share on other sites More sharing options...
Barand Posted May 26, 2006 Share Posted May 26, 2006 Something like[code]$sql = "select * from cdreviews ";if ($_GET['sort_by']) { $letter = $_GET['sort_by']; if ($letter=='#') { $sql .= "WHERE SUBSTRING(name, 1,1) IN ('0','1','2','3','4','5','6','7','8','9') ORDER BY name ASC"; } else { $sql .= "where name like '$letter%' ORDER BY name ASC"; }} else { $sql .= "order by dateadded DESC limit 10";}[/code] Link to comment https://forums.phpfreaks.com/topic/10362-selecting-columns-beginning-with-a-numeric-character/#findComment-39253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.