You are here: Re: how to merge veriables? « PHP Programming Language « IT news, forums, messages
Re: how to merge veriables?

Posted by Dave on 11/16/05 05:17

Dave <???@???.???> wrote in news:TpWdnZjPTM9lCufeRVn-ig@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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация