Woodburn2006 Posted June 13, 2006 Share Posted June 13, 2006 hello,i know how to select data from a SQL database fine by using: SELECT * from table where blah blah blahbut 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 appreciatedthanks Quote Link to comment https://forums.phpfreaks.com/topic/11869-selecting-from-mysql-field/ Share on other sites More sharing options...
joquius Posted June 13, 2006 Share Posted June 13, 2006 u mean[code]SELECT `field` FROM `table` WHERE `field` LIKE '%string%'[/code]? Quote Link to comment https://forums.phpfreaks.com/topic/11869-selecting-from-mysql-field/#findComment-45037 Share on other sites More sharing options...
AV1611 Posted June 13, 2006 Share Posted June 13, 2006 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 blahbut 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 appreciatedthanks[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11869-selecting-from-mysql-field/#findComment-45038 Share on other sites More sharing options...
Woodburn2006 Posted June 13, 2006 Author Share Posted June 13, 2006 thanks very much, worls perfectly Quote Link to comment https://forums.phpfreaks.com/topic/11869-selecting-from-mysql-field/#findComment-45099 Share on other sites More sharing options...
AV1611 Posted June 13, 2006 Share Posted June 13, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/11869-selecting-from-mysql-field/#findComment-45169 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.