Jump to content

grab all items that start with x


Onloac

Recommended Posts

Right now I have a link list a-z and 0-9.

you click one of those links and your taken to page listing all items that start with that character.

currently I'm using:

SELECT * FROM my_table where LEFT(`my_item`,1)='$show' ORDER BY my_title ASC

all I do right now is just add a link like ?show=a and everything that starts with a is listed.

 

Now here is my problem. I want to listen all items that start with a numeric value listed all on one page instead of being spread across 0-9.

 

If another solution becomes available I'd be more then happy to hear you out. But does anyone know how I can change my query to only list items that start with numbers?

Link to comment
Share on other sites

SELECT * FROM mytable WHERE mytextfield like 'a%';

% is a wildcard representing zero or more characters, just like * in unix. For a single character wildcard in SQL, use underscore (_).

 

Ooops, I see your question now.

SELECT * FROM mytable WHERE (myfield like '0%') or (myfield like '1%') or
(myfield like '2%') or (myfield like '3%') or (myfield like '4%') ...

Get the idea?

 

Link to comment
Share on other sites

I just double checked the LIKE docs and SQL does support Abdbuet's [0-9] syntax. His way is less typing.

 

OTOH, if you want to show all items that DON'T begin with letters, you can also do this:

SELECT * FROM mytable WHERE myfield like '[!a-zA-Z]%';

! is a negator.

 

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.