Re: PHP & MySQL -> Field Title

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Mon, April 30, 2007 12:47 am, Christian Haensel wrote:
> Good Morning guys and girls
>
> As I am rather lazy, I don't wanna do a data readout on my MySQL table
> in
> the following way with mysql_fetch_assoc()
>
> $data_item1    =    $data['xitem1'];
> $data_item2    =    $data['yitem2];
> ....
>
> I am trying to do the following:
>
> I have the correct number of fields in the table, which is 116. Now I
> want
> to use a for-loop and read teh data into a string, then shove it into
> another table, which has the exact same layout. I was thinking about
> something like
>
> for($i=0; $i<= 115; $i++) {
>     $data_item[$i]    =    $data[$i];
> }
>
> but now I have the problem with the field names and all... can someone
> point
> me into the right direction? All I have to so is move the contents of
> one
> field to the second database wich has the same layout as the first DB.
>
> Would be thankful for any help :o)

If it's MySQL you can bypass PHP altogether and get this done in about
1 second with something like:

SELECT INTO db2.whatever_table FROM db1.whatever_table;

This will essentially just copy the whole dang table.

Feel free to add field names in the syntax from:
http://dev.mysql.com
to change around the order of the fields or even combine/split fields
in simple MySQL functions.
Which you don't need for this task as you described, but somebody else
might.

Also feel free to add a WHERE clause to get only portions of the
table, which again you don't need, but somebody might.

So, really, using PHP for this is probably silly...

That said, you can use mysql_fetch_assoc and get the field names and
use array_keys and array_values to get the field names and values, if
you really really really need PHP to do something in between one db
and the next.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux