473,508 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to merge veriables?

This seems relatively simple, and I'm sure I've done it in the past, but
I can't seem to come up with a solution.

the following variables are sent via form using textbox inputs:
$var_1 = 'var1';
$var_2 = 'var2';
$var_3 = 'var3';

I want to use the variable values to create mySQL column names like so:

$arr = array($var_ ????)
foreach ($arr as &$value) {
mysql_query ("ALTER TABLE table_name ADD $value varchar(100) NOT
NULL");
}

The "????" indicates where I think I am getting stuck on how to capture
the form data into an array. The variables are identical character
length and numbered sequentially, so it is possible to do something like:

$i = 1;
while ($var_???? >= 1) {
mysql_query ("ALTER TABLE table_name ADD $value varchar(100) NOT
NULL");
i++
}

Again, the "????" indicates where I think I'm getting stuck on how to
cycle through the $var_x list.

I know this probably rudimentary and I feel dumb for not being able to
find the solution without coming here. I would really appreciate some
direction.

Thanks in advance
-Dave
Nov 22 '05 #1
3 1082
Dave wrote:
This seems relatively simple, and I'm sure I've done it in the past, but
I can't seem to come up with a solution.

the following variables are sent via form using textbox inputs:
$var_1 = 'var1';
$var_2 = 'var2';
$var_3 = 'var3';

I want to use the variable values to create mySQL column names like so:

$arr = array($var_ ????)
foreach ($arr as &$value) {
mysql_query ("ALTER TABLE table_name ADD $value varchar(100) NOT
NULL");
}

The "????" indicates where I think I am getting stuck on how to capture
the form data into an array. The variables are identical character
length and numbered sequentially, so it is possible to do something like:

$i = 1;
while ($var_???? >= 1) {
mysql_query ("ALTER TABLE table_name ADD $value varchar(100) NOT
NULL");
i++
}

Again, the "????" indicates where I think I'm getting stuck on how to
cycle through the $var_x list.

I know this probably rudimentary and I feel dumb for not being able to
find the solution without coming here. I would really appreciate some
direction.

Thanks in advance
-Dave

<input type="text" name="name[]" ... >

For each of the inputs. The brackets indicate all the values are to be
passed in the array named "name".
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 22 '05 #2
Dave <???@???.???> wrote in news:Tp********************@giganews.com:
This seems relatively simple, and I'm sure I've done it in the past,
but I can't seem to come up with a solution.

the following variables are sent via form using textbox inputs:
$var_1 = 'var1';
$var_2 = 'var2';
$var_3 = 'var3';

I want to use the variable values to create mySQL column names like
so:

$arr = array($var_ ????)
foreach ($arr as &$value) {
mysql_query ("ALTER TABLE table_name ADD $value varchar(100)
NOT
NULL");
}

The "????" indicates where I think I am getting stuck on how to
capture the form data into an array. The variables are identical
character length and numbered sequentially, so it is possible to do
something like:

$i = 1;
while ($var_???? >= 1) {
mysql_query ("ALTER TABLE table_name ADD $value varchar(100)
NOT
NULL");
i++
}

Again, the "????" indicates where I think I'm getting stuck on how to
cycle through the $var_x list.

I know this probably rudimentary and I feel dumb for not being able to
find the solution without coming here. I would really appreciate some
direction.

Thanks in advance
-Dave


I forgot to give the example I was thinking of when I typed the subject,
but I have a variable set for the actual number of variables. In
otherwords, if there are going to be 3 columns in the table, there is a
variable set to "3" like so:
$col_num = "3";
$i = 1;
while ($col_num >= i) {
$col_name = ('$col_num_' . $i);
mysql_query("ALTER TABLE table_name ADD $col_name varchar(100) NOT
NULL");
i++;
}

When I echo $col_name I am getting "$col_num_1", "$col_num_2" and
"$col_num_3". It's not returning the value of $col_num_1 but the actual
text "$col_num_1".

Again, thanks in advance.
Nov 22 '05 #3
Jerry Stuckle <js*******@attglobal.net> wrote in
news:Vr********************@comcast.com:

<input type="text" name="name[]" ... >

For each of the inputs. The brackets indicate all the values are to
be passed in the array named "name".


This got it!

Thanks Jerry!
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3229
by: William Wisnieski | last post by:
Hi Everyone, Access 2000 I have some code behind a button that performs a word merge with a query data source. The merge works fine. But what I'd like to do somehow is after the merge is...
5
4551
by: stemc © | last post by:
Hi there, In work, we often mail merge letters and post them to contacts. But more and more, we've been emailing information to people instead. So far, I've been writing a single generic...
2
3226
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
8
9495
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
5569
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
4
21657
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of...
16
4857
by: UDBDBA | last post by:
Hi All: I need some clarification on a MERGE statement. The database is on V8 FP12 (AIX) 64bit. The source table is tableA. The target is a View "FACT" with UNION ALL because of the 512 Gig...
4
7214
by: Tom Jones | last post by:
I have an application that was originally built using Visual Studio 2003 that I upgraded to Visual Studio 2005. When I attempt to build the *.msi file in the deployment project, I am getting a...
7
7225
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking...
24
7091
by: Henry J. | last post by:
My app needs to insert thousand value rows into a mostly empty table (data are read from a file). I can either use inserts, or use merge. The advantage of using merge is that in the few cases...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.