Jump to content

Strange filter problem.... ???


loki421

Recommended Posts

Hi all!

 

Firstly, I'd like to say a big hello to everyone :D

 

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 :)

 

 

Link to comment
Share on other sites

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 :P

 

Cheers :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.