Jump to content

Fetch from one quote mark to another


Go to solution Solved by Zane,

Recommended Posts

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 by KubeR
Link to comment
https://forums.phpfreaks.com/topic/287027-fetch-from-one-quote-mark-to-another/
Share on other sites

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.

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.

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

  • Solution

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 field

No. 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 by Zane
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.