Getting all values as one string

05-06-05, 02:52 PM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Getting all values as one string
I have been at this for a while, so i'll just explain: The sql query will result in one or more rows. i want to get a value from all the row and add them to a string, seperated by a comma before i add this to the screen.
The sql bit:
So if the query found 3 rows with the article_id values; art1, art2 and art3 the template assign would then be; and the result when i print this to the screen would be:
art1, art2, art3
How is this done in a simple way? Thanks!
|

05-06-05, 03:10 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
I assigned each article_id to the array $arts[] and then used implode() function to put all ids in a string seperated by ", "
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

05-06-05, 03:45 PM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I actually found a way to do this, but your way was alot easier, so that is what i'll use. Thanks. I do however have another problem. Here is the code i got to after a while. The values i get are actually ids refering to a rel name in another table, i need these names. So insted of the values; 1, 2, 3 i get name, name, name. You see?
Problem with this is that i only get the first name, not the others.
|

05-06-05, 04:18 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
maybe this problem is happing is because you are using the same variables names from outside the loop ($data, $row)
try changing them and use mysql_query() instead of mysql_db_query(). are you connecting to same DB 
mysql_db_query() is deprecated.
so try this:
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Last edited by NeverMind; 05-06-05 at 04:21 PM.
|

05-06-05, 04:52 PM
|
|
Newbie Coder
|
|
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ah, there we go. Things looking good. My script uses mysql_db_query alot. Should i rewrite and use mysql_query instead?
|

05-07-05, 07:17 AM
|
|
Newbie Coder
|
|
Join Date: Feb 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by Programme
Ah, there we go. Things looking good. My script uses mysql_db_query alot. Should i rewrite and use mysql_query instead?
|
i think theyre about the same, one is probably the same function with a newer name.
|

05-07-05, 12:57 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
Quote:
|
Originally Posted by Programme
Ah, there we go. Things looking good. My script uses mysql_db_query alot. Should i rewrite and use mysql_query instead?
|
it's better to replace them.
this is a quote from PHP manual:
Quote:
|
Note: This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db() and mysql_query() instead.
|
besides that you are only using one DB, so there is no need to reselect the same DB each time you execute a query.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

05-08-05, 09:40 AM
|
|
Coding Addict
|
|
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
Why don't just use table join to select all the writers in a single query?
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|