Jump to content

Archived

This topic is now archived and is closed to further replies.

Woodburn2006

Selecting from MySQL field

Recommended Posts

hello,

i know how to select data from a SQL database fine by using: SELECT * from table where blah blah blah

but what i am having problems with is that i need to be able to select data that contains a certain bit of text.

for example, if i have a column in a db table called 'Media'. the data within the column would be entered as 'cd, tape, floppy' so what i want is for the user to be able to click a button that says 'CD' and the query will notice that the MEDIA field will contain this bit of text, therefore will display it.

if the MEDIA field only containd 'cd' in it then i know that this would be shown using the standard SELECT query but i want the query to pick out just a bit of the text in the field.

any ideas?

any help would be appreciated

thanks

Share this post


Link to post
Share on other sites
u mean
[code]SELECT `field` FROM `table` WHERE `field` LIKE '%string%'[/code]
?

Share this post


Link to post
Share on other sites
Instead of echoing out the field data, echo out what you want if the select is true...

i.e.

[code]

select * from table where field like '%CD%'

IF ($row=mysql_fetch_array($result))
    {
     echo $CD='CD';
     //  don't do echo $CD=$row[field];
    }

[/code]

If you know the field it "true", then make it just say what you want, instead of trying to "pick" it out












[!--quoteo(post=383280:date=Jun 13 2006, 10:23 AM:name=Eggmoth)--][div class=\'quotetop\']QUOTE(Eggmoth @ Jun 13 2006, 10:23 AM) [snapback]383280[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hello,

i know how to select data from a SQL database fine by using: SELECT * from table where blah blah blah

but what i am having problems with is that i need to be able to select data that contains a certain bit of text.

for example, if i have a column in a db table called 'Media'. the data within the column would be entered as 'cd, tape, floppy' so what i want is for the user to be able to click a button that says 'CD' and the query will notice that the MEDIA field will contain this bit of text, therefore will display it.

if the MEDIA field only containd 'cd' in it then i know that this would be shown using the standard SELECT query but i want the query to pick out just a bit of the text in the field.

any ideas?

any help would be appreciated

thanks
[/quote]

Share this post


Link to post
Share on other sites
Just be carefull not to use the wildcards in a way that make the query too "broad" and brings back false hits... if that becomes a problem, you will ahve to go to a regex to narrow the query...

Share this post


Link to post
Share on other sites

×

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.