Search code examples
phpmysqldatabasesubstringclob

How to take only a fragment of data from my database?


I am working with PHPMyadmin and I have a field called The_Job, in which there is a vast description of a job. I have created a .php document where I have added a dinamic table with all the rows from my database. The_job is one of them, and what I want to do is to add only a fragment of the data from the database field The_Job into the table.

Which means that I have to somehow cut down the text to a limited "x" number of characters and add "..." at the end.

How can I do that?


Solution

  • You did not provide any data and example of what you tried, but I assume that you want a few of characters from the field and then ... The SQL function LEFT is what you are looking for:

    SELECT CONCAT(SUBSTR(The_Job, x, y),'...') FROM table
    

    This will substract characters x to y (so you would write something like SUBSTR(The_Job, 1, 10) for character 1 to 10

    or

    SELECT CONCAT(LEFT(The_Job, x),'...') FROM table
    

    This will select first x characters of The_Job.

    UPDATE: I changed the operator || to CONCAT.