FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Inserting PHP multidimensional arrays into a mySQL database





flatliner
Well as the tilte describes I need to know how to insert a multidimensional arrays into a mySQL database, the table has 14 columnes. I not sure how to do this, here is a sippent of the large multidimensional array.

Code:


Code removed by user



Kind Regards
Ciaran Mc Cann
AOP Web Development
you can use for loop then foreach loop..
flatliner
not really sure what ya mean , could ya give me some explain code or just explain it more. thanks
JayBee
Code:
<?php
function insert_row($row) {
   // here goes your implementation
   // how to insert single array to mysql database
}

foreach($your_multi_array as $row) {
   insert_row($row);
}
?>





second very very bed solution is
Code:
<?php
$one_string = serialize($your_big_multidimensional_array);
// save $one_string to TEXT field in your database :D
// DONT DO THAT THIS WAY! I only kidding you.
?>
flatliner
Could you explain that abit more, I dont see how that would work. Maybe use my code above and sub it into the syntax formula to explain it abit better
JayBee
you didn't post any code, only print_r/vardump output

Do you know how to insert an array to database?

something like this code?
Code:
<?php
$ar = array("a",1,"CDC-989");
$query = "INSERT INTO foo_table (foo1,foo2,foo3) VALUES ('%s', '%s', '%s')";
$query = sprintf($query, $ar[0], $ar[1], $ar[2]);
mysql_query($query);
?>
flatliner
no i dont have a clue on arrays really let alone inserting them into a mysql database.
JayBee
My question is, why you want know how to insert multidimensional array, if you dont know, how to insert single array?

Ask correct questions.
flatliner
dude the question here isnt what I know or why I need to know it (well not really) but that I need to know it for a certain task, so if ya know could ya please post me a good example of how to insert a multidimensional arrays into a mysql. thanks , I need step by step walk through the code, if poissable.
JayBee
here is how to insert one row

http://php.net/manual/en/function.mysql-query.php#62227
(google search "php mysql")
and my post before tels how to walk throw the array
http://frihost.com/forums/viewtopic.php?p=628803#628685
(the first part of course)

is this good enough for you? Very Happy
flatliner
no not really. ha , ah no its grand I got a well exampled answer and solution code to my problem on another forum. I am lost when it comes to arrays and data mining.

Thanks to every1 who helped.

Yours Thankfully
Ciaran Mc Cann
Related topics
Mysql database size?
A very good PHP MySQL Tutorial
insert data to mySQL database problem
Delete data from MySQL database problem!!
Problem connecting to MySQL database with PHP [RESOLVED]
Need Help with mysql database of DragonflyCMS
Help importing CSV file into MySQL database
How to search in a MySQL - database
Finding the newest entry in a mysql database?
mysql database table structure
Connecting to 2 different Mysql database and tables?
PHP that creates subdomain, ftp account, and mysql database?
Changing entries in MySQL database
mysql database schema, blogs, forums and their text
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.