Jump to content


Photo

Selecting from MySQL field


  • Please log in to reply
4 replies to this topic

#1 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 13 June 2006 - 02:23 PM

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

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 13 June 2006 - 02:32 PM

u mean
SELECT `field` FROM `table` WHERE `field` LIKE '%string%'
?
z..z..z..z..z..z..z..z..

#3 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 June 2006 - 02:32 PM

Instead of echoing out the field data, echo out what you want if the select is true...

i.e.


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

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


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) View Post[/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]


#4 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 13 June 2006 - 04:36 PM

thanks very much, worls perfectly

#5 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 June 2006 - 06:46 PM

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...






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users