Trying to load an multidimensiona l array into a MySQL table with columns as
follows,
level1,level2,l evel3,illust,it em,description, partNo,qua,pric e,remarks,weigh t
,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,i tem,description ,partNo,qua,pri ce,remarks,weig h
t,size,mass) VALUES
('$level1','$le vel2','$level3' ,'$illust','$it em','$descripti on','$partNo',' $
qua','$price',' $remarks','$wei ght','$size','$ mass')";
$result = mysql_query($qu ery2) 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 2824
Stephen Preston wrote: Trying to load an multidimensiona l array into a MySQL table with columns as follows,
level1,level2,l evel3,illust,it em,description, partNo,qua,pric e,remarks,weigh t ,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,i tem,description ,partNo,qua,pri ce,remarks,weig h t,size,mass) VALUES ('$level1','$le vel2','$level3' ,'$illust','$it em','$descripti on','$partNo',' $ qua','$price',' $remarks','$wei ght','$size','$ mass')"; $result = mysql_query($qu ery2) 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*******@attgl obal.net
=============== ===
Message-ID: <aM************ ********@comcas t.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($r ow));
$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($qu ery1)
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,i tem,description ,partNo,qua,pri ce,remarks,weig ht,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($qu ery2) or die("Couldn't insert data.");
}
# $result = mysql_query($qu ery2) 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($qu ery1) 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,i tem,description ,partNo,qua,pri ce,remarks,weig ht,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($qu ery2) or die("Couldn't insert data."); } # $result = mysql_query($qu ery2) 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*******@attgl obal.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` and `lessons`
Lets say Courses has fields
CourseID(PK), Date, Name, RunBy, Status
The lessons table is related to the Courses table in that a Course can have
|
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
inside loop
$q=mysql_query("SHOW FIELDS FROM table" ) or die ("Query failed");
|
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 help do the most basic
things.
One of the "basic" things I haven't been able to find out how to do is how
to delete an item from a multidimensional array object and resize it
afterwards.
It seems so easy to conceive of the code to delete...
|
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 contains 6months' names.
source array contains source of that month.
$table_row conatins editions of particular source.
looking forward to get help from anyone
Thanks
Here is the code..
| |
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 from 2 different tables.i am getting the output properly but only thing is tht i need to sort the o/p as per name
here fid=6 is designation..uid is the id of the user ,fid=3 is Name of the person,fid=11 is for extension ,fid=1 is research...
|
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 would be slower for jsp to handel.
Okay here is an example of my multidimensional array (only part of it)(bottom of the post). It works fine I can call any of the 3rd dimension without trouble.
Now How would I go about printing something like...
|
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 something like this?
var $userArray = array(array());
|
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 400
2008 West 500
2008 East 600
2008 North 700
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |