Jump to content

[SOLVED] multiple values from single column


unknown1

Recommended Posts

Hello all, I created a script that stores multiple values in a single mysql column

and I'm trying to echo each out without the values being separated by a comma and or having to go $v[0] $v[1].... can someone explain how I can echo each value of the column out on a new line.

 

$value = explode(",",$row['some_value']);

 

but it just says array when I echo it out...

 

Thanks in advance!!

Link to comment
Share on other sites

Hello all, I created a script that stores multiple values in a single mysql column

and I'm trying to echo each out without the values being separated by a comma and or having to go $v[0] $v[1].... can someone explain how I can echo each value of the column out on a new line.

 

$value = explode(",",$row['some_value']);

 

but it just says array when I echo it out...

 

Thanks in advance!!

 

Not 100% sure if that's even right... should I even be treating the values of the column as an array or am I just trying to format the values after.... what id the best way to go about this??

 

 

Link to comment
Share on other sites

Having to store values like this in mysql is usually a sign of poor database design, that being said.. The reason why you're getting 'Array' is because explode() returns an Array. If all you want to do is to echo out all the values separated by a space instead of a comma, why don't you just do:

 

echo str_replace(',', ' ', $row['some_value']);

Link to comment
Share on other sites

Having to store values like this in mysql is usually a sign of poor database design, that being said.. The reason why you're getting 'Array' is because explode() returns an Array. If all you want to do is to echo out all the values separated by a space instead of a comma, why don't you just do:

 

echo str_replace(',', ' ', $row['some_value']);

 

Should I not be treating the column as an array?? If not why??

Would exploding the values not do the same thing?

 

I am just trying to separate each value onto a new line... and I guess I could just go

echo str_replace(',', ' \n', $row['some_value']);

or would that work??

 

Link to comment
Share on other sites

Having to store values like this in mysql is usually a sign of poor database design, that being said.. The reason why you're getting 'Array' is because explode() returns an Array. If all you want to do is to echo out all the values separated by a space instead of a comma, why don't you just do:

 

echo str_replace(',', ' ', $row['some_value']);

 

Should I not be treating the column as an array?? If not why??

Would exploding the values not do the same thing?

 

I am just trying to separate each value onto a new line... and I guess I could just go

echo str_replace(',', ' <br>', $row['some_value']);

or would that work??

 

The reason I ask if I can somehow treat the values in the column as an array is because I also need to compare each value to other values in another table row in the database... so I would need be checking them one value at a time.

Link to comment
Share on other sites

BTW I did it like this because it's an invite script that saves the emails invited to the database in one column... the reason for this is because the invite sends mass emails and it stores multiple emails

to that one single column. Then I want to do a check on another table row to see what emails are ones that have actually signed up....

Link to comment
Share on other sites

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.