loki421 Posted August 24, 2011 Share Posted August 24, 2011 Hi all! Firstly, I'd like to say a big hello to everyone Right, so I have a bit of a strange problem. I get no error, but my page stalls. So here's what I've got, a simple alphabet (A-Z) in capitals at the top of the page, created by: $alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); // then further down the page I have it looped as so: <?php foreach($alphabet as $link): ?> <a href="suppliers.php?filter=<?php echo $link; ?>"> <?php echo $link; ?> </a> | <?php endforeach; ?> So that's all cool. I then have this at the top of the page: $the_suppliers = (isset($_GET['filter']) && preg_match("/[^A-Z]*/",$_GET['filter'])) ? $suppliers -> get_all($_GET['filter']) : $suppliers -> get_all('all'); Now I have preg_match() in there as I was using ctype_alpha() to check for only alphabetical chars, and thought that might be my problem, but still get it with preg_match(); Anyway, my class method (get_all()) is: public function get_all($filter){ global $database; if($filter == 'all'){ $sql = "SELECT * FROM " . self::$table . " WHERE on_web = 1 ORDER BY RAND() LIMIT 10"; }else{ $sql = "SELECT * FROM " . self::$table . " WHERE on_web = 1 AND LEFT(name,1) = '" . $database -> sql_prep($filter) . "'"; } return self::find_by_sql($sql); } Now this works fine for b-z, but for some reason when the filter=A it just hangs..... I have ran the sql in phpmyamin and it returns the result straight away, so I know it's not the sql. Does anyone here know where I might be going wrong here? It's very odd and I've never come across this before, and not getting an error doesn't really help much. Any suggestions or pointers will be gratefuly received Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 24, 2011 Share Posted August 24, 2011 Not sure why it works with B-Z, but the pattern should probably be: "/[A-Z]/" Quote Link to comment Share on other sites More sharing options...
loki421 Posted August 24, 2011 Author Share Posted August 24, 2011 Not sure why it works with B-Z, but the pattern should probably be: "/[A-Z]/" Thanks for the quick reply dude, but just this second fixed it, typical hey! lol For anyone else out there who has a similar problem I maaged to fix this by turning it to lower case as so: <?php foreach($alphabet as $link): ?> <a href="suppliers.php?filter=<?php echo strtolower($link); ?>"> <?php echo $link; ?> </a> | <?php endforeach; ?> This then passes it over to the class in lower case and that works lovely. Strage hey? :s Even though I ran the sql in uppercase when I was testing. Never mind hey, just one of those odd errors Cheers Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 24, 2011 Share Posted August 24, 2011 Glad you found the issue. Just FYI (less typing and less code): $alphabet = range('A', 'Z'); Quote Link to comment Share on other sites More sharing options...
loki421 Posted August 24, 2011 Author Share Posted August 24, 2011 Glad you found the issue. Just FYI (less typing and less code): $alphabet = range('A', 'Z'); Ah yes, range(), that's cool. So much to squeeze into my noggin Cheers again dude Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.