KubeR Posted March 17, 2014 Share Posted March 17, 2014 (edited) Hi,I have no idea if there is a way to do it,but is it possible to make MySQL fetch only the data between the quotation marks in a specific place in the field ?for instance :if I have in the database - [/td][td]Column Row "This is content 1","This is content 2","This is content 3" And I want to fetch only "This is content 2",How do I fetch it ? Edited March 17, 2014 by KubeR Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/ Share on other sites More sharing options...
trq Posted March 17, 2014 Share Posted March 17, 2014 Why are you storing your data like that in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472875 Share on other sites More sharing options...
KubeR Posted March 17, 2014 Author Share Posted March 17, 2014 Why are you storing your data like that in the first place?To split parts of the content,because the space on the website is too small for big content,and I want to split it into pages/parts. So instead of fetching the whole content,I want to fetch only the small part. Now of course I can just use comma to seperate,but if the content will contain comma's (which probably will),it will recognize the rest as another content. So as alternative,I want to encode the quatation marks in the content to HTML code(") and by this find the start and end of the content. But,after a little research,I found that I can encode commas too,to ‚ The problem is that I have no idea how to find these commas and/or skip and find the next. Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472882 Share on other sites More sharing options...
jazzman1 Posted March 17, 2014 Share Posted March 17, 2014 So instead of fetching the whole content,I want to fetch only the small part. Why don't you use some aplication language function to achieve this? "Wordwrap" in php is a good option. Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472886 Share on other sites More sharing options...
Barand Posted March 17, 2014 Share Posted March 17, 2014 Normalize your data correctly and problem goes away Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472918 Share on other sites More sharing options...
KubeR Posted March 17, 2014 Author Share Posted March 17, 2014 Why don't you use some aplication language function to achieve this? "Wordwrap" in php is a good option.Because I believe it can be solved simply with MySQL. The main problem isn't in the display,but amount of data which is being passed from the database to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472927 Share on other sites More sharing options...
Psycho Posted March 17, 2014 Share Posted March 17, 2014 @KubeR, What the others are getting at is that you are trying to solve the wrong problem. It 'appears' you have made some decisions based upon your current knowledge and your comfort zone. There are many reasons why your current method of storing that data is problematic. Your current problem is just the tip of the iceberg. You need to revise your database schema to do this properly. If you provide details on what the information is that you are storing and the business rules around it, we can help to provide a revised schema. Otherwise, you are going to be hard pressed to find anyone (knowledgeable) on this forum to help you since doing so would only enforce a bad behavior. Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472931 Share on other sites More sharing options...
Solution Zane Posted March 17, 2014 Solution Share Posted March 17, 2014 (edited) Now of course I can just use comma to seperate,but if the content will contain comma's (which probably will),it will recognize the rest as another content.This is one of the many reasons you shouldn't store multiple values as everyone is suggesting. There are too many things that can go wrong with a setup like this. I want to fetch only "This is content 2",How do I fetch it ?To answer you question though, is it possible to make MySQL fetch only the data between the quotation marks in a specific place in the fieldNo. Not in the way that you are trying. The only way to get Item 2, is to receive all of the info and use PHP to explode by the comma and then it's as simple as reading $thedata[1] Ideally, you want to do any and all filtering on the MySQL side first, which is why you asked this question to begin with. So do yourself a favor and read a tutorial on normalization, table joins, foreign and primary keys, etcetera. Start by reading this thread here, http://stackoverflow.com/questions/2800104/sql-query-with-multiple-values-in-one-column Edited March 17, 2014 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/#findComment-1472936 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.