laravel retrieve multiple values separated by commas in a column as separate values

001221

Hi I have a column in my database called client_website in my client database and in some cases there are multiple website links, these are separated by commas as so:

www.link1.com, www.link2.com, www.link3.com 

I query the my Projects controller first as I bring

   @foreach ($clients as $client)   
   {{ $client->client_name }}
    {{ $client->email }}
   {{ $client->client_website }}
   @endforeach

It literally is printed out as below:

www.link1.com, www.link2.com, www.link3.com 

and when I wrap it in a <a> tag it fills them the href with all three links, is there anyway I can strip about the commas and spilt them into three separate entities?

brfrth

You would have to put a second foreach in there which is sort of dirty but it does work. So you would put another foreach and then on the exploded string of websites and that will make an anchor for all websites.

Imagining these are the clients websites:

www.link1.com, www.link2.com, www.link3.com

Your code would be like this:

@foreach ($clients as $client)   
   {{ $client->client_name }}
   {{ $client->email }}
      @foreach (explode(', ', $client->client_website) as $client_website)
          {{ $client_website }}
      @endforeach
@endforeach

This would output:

Client nameClient emailwww.link1.comwww.link2.comwww.link3.com

You can then add all sorts of styling around it. It would work for any number of clients and any number of websites. Just notice that the list of websites needs to be seperated by commas with a trailing space.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

how to separate comma separated values in oracle 11G

분류에서Dev

unable to retrieve field values from object laravel

분류에서Dev

How to extract comma separated column values from database using php

분류에서Dev

sending multiple selected values comma-separated to a stored procedure

분류에서Dev

Split Pandas Dataframe into separate pieces based on column values

분류에서Dev

Multiply column values in SQL, then add all the values - Laravel 4

분류에서Dev

SQL aggregate multiple values in a column then Pivot

분류에서Dev

Convert MySql column with multiple values to proper table

분류에서Dev

Separate values based on record

분류에서Dev

Retrieve values from a JSON

분류에서Dev

pandas: populate an empty column in a dataframe with values from multiple dataframes based on similar values in one column

분류에서Dev

Jquery looking for widget to hold multiple string values separated by white space or comma as object

분류에서Dev

How to count the number of character in a comma separated line where commas within delimiter are not to be counted as separate?

분류에서Dev

How efficient to retrieve multiple values from multiple tables from mysql database using php

분류에서Dev

retrieve xml values using powershell

분류에서Dev

Retrieve class values from selectCheckboxMenu

분류에서Dev

Grabbing all rows from a database that have specific column values in laravel

분류에서Dev

R: Extract rows from a dataframe where values from one column occur in a separate vector

분류에서Dev

Get maximum of comma-separated values in a cell

분류에서Dev

Get values from the pipe separated file

분류에서Dev

Filling in column based on column values

분류에서Dev

How to return multiple values

분류에서Dev

MATLAB Multiple Maximum Values

분류에서Dev

SCSS calculation with multiple values

분류에서Dev

conditional assignment of multiple values

분류에서Dev

Aggregating monthly column values into quarterly values

분류에서Dev

retrieve database values and then replace values with images outside of database

분류에서Dev

Keep all values added by a method in a separate variable

분류에서Dev

How to separate keys of duplicate values in an array

Related 관련 기사

  1. 1

    how to separate comma separated values in oracle 11G

  2. 2

    unable to retrieve field values from object laravel

  3. 3

    How to extract comma separated column values from database using php

  4. 4

    sending multiple selected values comma-separated to a stored procedure

  5. 5

    Split Pandas Dataframe into separate pieces based on column values

  6. 6

    Multiply column values in SQL, then add all the values - Laravel 4

  7. 7

    SQL aggregate multiple values in a column then Pivot

  8. 8

    Convert MySql column with multiple values to proper table

  9. 9

    Separate values based on record

  10. 10

    Retrieve values from a JSON

  11. 11

    pandas: populate an empty column in a dataframe with values from multiple dataframes based on similar values in one column

  12. 12

    Jquery looking for widget to hold multiple string values separated by white space or comma as object

  13. 13

    How to count the number of character in a comma separated line where commas within delimiter are not to be counted as separate?

  14. 14

    How efficient to retrieve multiple values from multiple tables from mysql database using php

  15. 15

    retrieve xml values using powershell

  16. 16

    Retrieve class values from selectCheckboxMenu

  17. 17

    Grabbing all rows from a database that have specific column values in laravel

  18. 18

    R: Extract rows from a dataframe where values from one column occur in a separate vector

  19. 19

    Get maximum of comma-separated values in a cell

  20. 20

    Get values from the pipe separated file

  21. 21

    Filling in column based on column values

  22. 22

    How to return multiple values

  23. 23

    MATLAB Multiple Maximum Values

  24. 24

    SCSS calculation with multiple values

  25. 25

    conditional assignment of multiple values

  26. 26

    Aggregating monthly column values into quarterly values

  27. 27

    retrieve database values and then replace values with images outside of database

  28. 28

    Keep all values added by a method in a separate variable

  29. 29

    How to separate keys of duplicate values in an array

뜨겁다태그

보관