473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Get string to become a variable, not print to screen

170 100+
I have been stuck on a problem for 3 hours straight now. I am going crazy
because this should be simple. (I am a relatively new mysql/php user, though)

I have a mysql table with a field containing email addresses. I want to
get all the addresses in that field and concatenate them into a string
like

email1;email2; etc so that each email address is separated with a semicolon.

I have found code to make this happen and print it onto a screen. But I
don't want it printed on a screen. I want to just put it into a variable,
so I can use the variable later. What do I do? Below is the code
Expand|Select|Wrap|Line Numbers
  1. $query2="SELECT * FROM tablename";
  2.  $result=mysql_query($query2);
  3. while($row = mysql_fetch_array($result)){
  4.         echo $row['address']."; ";
  5. }
  6.  
Many thanks
Nov 24 '06 #1
2 2183
ronverdonk
4,258 Expert 4TB
I have been stuck on a problem for 3 hours straight now. I am going crazy
because this should be simple. (I am a relatively new mysql/php user, though)

I have a mysql table with a field containing email addresses. I want to
get all the addresses in that field and concatenate them into a string
like

email1;email2; etc so that each email address is separated with a semicolon.

I have found code to make this happen and print it onto a screen. But I
don't want it printed on a screen. I want to just put it into a variable,
so I can use the variable later. What do I do? Below is the code
Expand|Select|Wrap|Line Numbers
  1. $query2="SELECT * FROM tablename";
  2.  $result=mysql_query($query2);
  3. while($row = mysql_fetch_array($result)){
  4.         echo $row['address']."; ";
  5. }
  6.  
Many thanks
When you mean actually concatenate, without any extra separator, do this: [php]
$str = "";
while($row = mysql_fetch_array($result)){
$str = .= $row['address']."; ";
}
[/php]
When you want to append them in an array for later extraction, do this:[php]
$arr = array();
while($row = mysql_fetch_array($result)){
$arr[] = $row['address']."; ";
}
[/php]
Ronald :cool:
Nov 24 '06 #2
beary
170 100+
Many thanks for this Ron.

[quote=ronverdonk]When you mean actually concatenate, without any extra separator, do this: [php]
$str = "";
while($row = mysql_fetch_array($result)){
$str = .= $row['address']."; ";
}
[/php]
Nov 24 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andy R. | last post by:
Hello everyone, I've spent quite some time now, looking for some information on how to get this done, sadly none has helped me much, though. I have a bit of java scrpt on a webpage (.php) to...
12
by: Kamilche | last post by:
I was looking for a way to speed up detecting invalid characters in my TCP string, and thought of yet another use for the translate function! If you were to 'translate out' the bad characters, and...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
3
by: Michel Gilbert | last post by:
Hi, i need some help with string. I like to build a string containing some other variable name and use the variable as if the on inside as been transfom to there contain: Exemple dim a as...
5
by: Chris H | last post by:
Okay, I am trying to us a varialble with a list of number values as my data for an array, yet when I do this it doesnt return any values from the array, i was able to temporarily fix the proble by...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
2
by: sophie_newbie | last post by:
Hi, I'm wondering if its possible to copy all of stdout's output to a string, while still being able to print on screen. I know you can capture stdout, but I still need the output to appear on the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.