Trying to load an multidimensional array into a MySQL table with columns as
follows,
level1,level2,level3,illust,item,description,partN o,qua,price,remarks,weight
,size,mass
the array first line is $input[0][level1]Engine
the array secondline is $input[0][level2]Cylinder Head
etc..
A 'foreach' inside a 'foreach' echo of the array gives the following, which
is correct.
0, level1, Engine
0, level2, Cylinder Head
0, level3,
0, illust, 001.pdf
0, item, 1
0, description, Casting
0, partNo, 238356
0, qua, 1
0, price, 1,245.00
0, remarks, This is for the Z350 series
0, weight, 5
0, size, 5x5x5
0, mass, 37
1, level1, Engine
1, level2, Cylinder Head
1, level3,
1, illust, 001.pdf
1, item, 2
1, description, Valve, inlet
1, partNo, 452790
1, qua, 4
1, price, 5.46
1, remarks, This is for the Z350 series
1, weight, 5
1, size, 5x5x5
1, mass, 37
2, level1, Engine
2, level2, Cylinder Head
2, level3,
2, illust, 001.pdf
2, item, 3
2, description, Valve, exhaust
2, partNo, 345436
2, qua, 4
2, price, 5.99
2, remarks, This is for the Z350 series
2, weight, 5
2, size, 5x5x5
2, mass, 37
etc..
I have used the print_r to see all the data in the array also.
I've tried the extract() function on the first key which I assume is also an
array, inside and outside the loop to get at the column headings.
I've tried allsorts of while and for loops but can't seem to work out how to
get down to the last key to get the following statement to work. I'm trying
the get the array to work through the first key [0] to fill the row, then
the next key [1] to fill the next row in the table etc..
$query2 = "INSERT INTO $tableName
(level1,level2,level3,illust,item,description,part No,qua,price,remarks,weigh
t,size,mass) VALUES
('$level1','$level2','$level3','$illust','$item',' $description','$partNo','$
qua','$price','$remarks','$weight','$size','$mass' )";
$result = mysql_query($query2) or die("Couldn't insert data.");
If I knock out the loops and have the above as a single statement, I can get
the last row of records into the table.
Hope someone can put a novice out of his misery.
Thanks
Stephen 5 2771
Stephen Preston wrote: Trying to load an multidimensional array into a MySQL table with columns as follows,
level1,level2,level3,illust,item,description,partN o,qua,price,remarks,weight ,size,mass
the array first line is $input[0][level1]Engine the array secondline is $input[0][level2]Cylinder Head etc..
A 'foreach' inside a 'foreach' echo of the array gives the following, which is correct.
0, level1, Engine 0, level2, Cylinder Head 0, level3, 0, illust, 001.pdf 0, item, 1 0, description, Casting 0, partNo, 238356 0, qua, 1 0, price, 1,245.00 0, remarks, This is for the Z350 series 0, weight, 5 0, size, 5x5x5 0, mass, 37 1, level1, Engine 1, level2, Cylinder Head 1, level3, 1, illust, 001.pdf 1, item, 2 1, description, Valve, inlet 1, partNo, 452790 1, qua, 4 1, price, 5.46 1, remarks, This is for the Z350 series 1, weight, 5 1, size, 5x5x5 1, mass, 37 2, level1, Engine 2, level2, Cylinder Head 2, level3, 2, illust, 001.pdf 2, item, 3 2, description, Valve, exhaust 2, partNo, 345436 2, qua, 4 2, price, 5.99 2, remarks, This is for the Z350 series 2, weight, 5 2, size, 5x5x5 2, mass, 37
etc..
I have used the print_r to see all the data in the array also. I've tried the extract() function on the first key which I assume is also an array, inside and outside the loop to get at the column headings.
I've tried allsorts of while and for loops but can't seem to work out how to get down to the last key to get the following statement to work. I'm trying the get the array to work through the first key [0] to fill the row, then the next key [1] to fill the next row in the table etc..
$query2 = "INSERT INTO $tableName (level1,level2,level3,illust,item,description,part No,qua,price,remarks,weigh t,size,mass) VALUES ('$level1','$level2','$level3','$illust','$item',' $description','$partNo','$ qua','$price','$remarks','$weight','$size','$mass' )"; $result = mysql_query($query2) or die("Couldn't insert data.");
If I knock out the loops and have the above as a single statement, I can get the last row of records into the table.
Hope someone can put a novice out of his misery.
Thanks Stephen
Stephen,
How about showing us the failing code? It would be much easier to
troubleshoot what's going wrong.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
Message-ID: <aM********************@comcast.com> from Jerry Stuckle
contained the following: How about showing us the failing code? It would be much easier to troubleshoot what's going wrong.
And how did the data get into the multi-dimensional array in the first
place?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Its not, really, its in $table[$row][$col] = $value format, at least if
i understand his post correctly. It also sounds like an interation
problem? I can't rightly tell if its trouble getting the last key from
table ( $row from $table ) or last key from row ($col from each $row).
In either case:
$i = 0; to $i < n, iterates n times. Make sure you're iterating to the
correct amount
foreach($table as $row) {
$columns = implode(... array_keys($row));
$values = implode(... array_values($row));
$query = "insert into table ($columsn) values ($values)";
}
or
foreach($table as $row) {
"insert into table (col1, col2, ...) values ($row[level1], $row[level2]
....)";
}
Hope that helps?
Hi
Thanks to you all for replying, and sorry if my explaination was garbled.
The code for the section is as follows.
The first part empties the table first (which it does). After persevering
further last night the code below empties the contents of the table, and the
$result inside the brackets fills one row of the MySQL table with the first
row of the array, then issues the 'Couldn't insert data'.
If I swap the $result is outside the brackets (# commented out below), the
table is emptied again and then the last row of the array fills one row of
the table. 'Couldn't insert data' is not issued though this time.
if(isset($_POST['dataok']))
{
$input = $_POST[input];
include("dataup.inc");
$query1 = "DELETE FROM $tableName";
$result = mysql_query($query1)
or die("Couldn't delete the data.");
echo "All data within $tableName has been deleted!!!<p>";
foreach($input as $row)
{
$query2 = "INSERT INTO $tableName
(level1,level2,level3,illust,item,description,part No,qua,price,remarks,weight,size,mass)
VALUES
('$row[level1]','$row[level2]','$row[level3]','$row[illust]','$row[item]','$row[description]','$row[partNo]','$row[qua]','$row[price]','$row[remarks]','$row[weight]','$row[size]','$row[mass]')";
$result = mysql_query($query2) or die("Couldn't insert data.");
}
# $result = mysql_query($query2) or die("Couldn't insert
data.");
exit();
} # endif
Still trying to understand Richards first example (my lack of
understanding), not his explaination I think.
Thanks
Stephen
Stephen Preston wrote: Hi
Thanks to you all for replying, and sorry if my explaination was garbled. The code for the section is as follows. The first part empties the table first (which it does). After persevering further last night the code below empties the contents of the table, and the $result inside the brackets fills one row of the MySQL table with the first row of the array, then issues the 'Couldn't insert data'. If I swap the $result is outside the brackets (# commented out below), the table is emptied again and then the last row of the array fills one row of the table. 'Couldn't insert data' is not issued though this time.
if(isset($_POST['dataok'])) { $input = $_POST[input]; include("dataup.inc"); $query1 = "DELETE FROM $tableName"; $result = mysql_query($query1) or die("Couldn't delete the data."); echo "All data within $tableName has been deleted!!!<p>";
foreach($input as $row) { $query2 = "INSERT INTO $tableName (level1,level2,level3,illust,item,description,part No,qua,price,remarks,weight,size,mass) VALUES ('$row[level1]','$row[level2]','$row[level3]','$row[illust]','$row[item]','$row[description]','$row[partNo]','$row[qua]','$row[price]','$row[remarks]','$row[weight]','$row[size]','$row[mass]')"; $result = mysql_query($query2) or die("Couldn't insert data."); } # $result = mysql_query($query2) or die("Couldn't insert data.");
exit(); } # endif
Still trying to understand Richards first example (my lack of understanding), not his explaination I think.
Thanks Stephen
Rather than just saying "Couldn't insert data", you need to find out WHY
it couldn't insert it. Try mysql_error() and see what it says.
I suspect it has to do with your values; amongst other things, numeric
values should not have quotes around them.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
================== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Smithz |
last post by:
Hi there.
Because of the lack of a Union query in MySQL 3 I have decided to take the
approach where I populate two arrays with values from similar tables in DB.
In this case they are `courses`...
|
by: pauld |
last post by:
from a MySQL DB i want to get a multidimensional array that i can loop
through
either key =field name value = array of ENUM options
or array =field name, array= ENUM options and increment x...
|
by: TheKeith |
last post by:
I can't figure out why this doesn't work:
---------------------------------------------
greeting = new Array();
greeting = "hey";
greeting = "bye";
trace(greeting + greeting);
|
by: |
last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to...
|
by: shailajaAdiga |
last post by:
Hi All,
there are 4 different categories which each month will bw updated. In each category(source),there are many editions. I have to display 6months updates. its like one is month array which...
|
by: pradeepjain |
last post by:
Hii,
i need help in sorting multidimensianal array...
i Read the multi sort function cld not use tht so i need help..This is the code.
here the problem is tht i need to take out values...
|
by: Jezternz |
last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
|
by: KDawg44 |
last post by:
Hi,
Is there a way to get a multidimensional associative array with the
entire result set? I would like to get a an array like this:
resultsArray
How can I accomplish this? Can I do...
|
by: mouac01 |
last post by:
Let's say I have this MySQL table.
Year Region Amount
2007 West 100
2007 East 200
2007 North 300
2007 South ...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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
| |