insert dinamic data into mysql table

Hello everyone.
I need help and hope that someone will help me.
I have three tables (kolicina, naziv_materijala and skladiste). In table kolicina and naziv_materijala are two fields (id, kolicina in one table, and in another id, naziv_materijala). In table skladiste are three fields (id, naziv_materijala, tvrtka) and 750 rows (yes 750 - this is not mistake). My problem is that I don't now how to put data from tables kolicina and naziv_materijala into table skladiste!

My attempt:
- first I will get data from two tables - thats i OK
$sql="SELECT * FROM kolicina ORDER BY id DESC";
if (!$q=mysql_query($sql))
echo "error<br>" . mysql_query();
if (mysql_num_rows($q)==0)
echo "<br><span>there is nothing</span><br><br>";
} else {
while ($redak=mysql_fetch_array($q))
echo $kolicina."!!<br>"; // this is for testnig purpose
$sql2="SELECT * FROM naziv_materijala ORDER BY id DESC";
if (!$q=mysql_query($sql2))
echo "error<br>" . mysql_query();
if (mysql_num_rows($q)==0)
echo "<br><span>there is nothing</span><br><br>";
} else {
while ($redak2=mysql_fetch_array($q))
echo $nm."!!<br>"; // this is for testnig purpose


7 // kolicina
33 // kolicina
28 // kolicina
1 // kolicina
12 // kolicina
Zdenac // naziv_materijala
Spojnica // naziv_materijala
Nogar // naziv_materijala
Zica // naziv_materijala
y-spojni // naziv_materijala
/////////////////////////// OK

////////////////////////////////AND NOW, THIS IS MY PROBLEM////////////////
- how to put values from result in the table skladiste
how to build query that:
- in table skladiste in column firma put values of variable $kolicina WHERE rows naziv_materijala is values of variable $nm?

////my attempt - is not working
$sql3="UPDATE skladiste SET firma='$kolicina' WHERE naziv_materijala='$nm'";
if (mysql_query($sql))//....

This is my attempt, but if someone has a better idea or solution I will be grateful. It is only important that is successfully solved.

If something is not clear enough, just ask and I will provide more details.

Thanks in advance..
You need to try based on this update command where two tables are updated by single command

In your tables there is a field ID. Is it the field by which all records of three table can be linked ?
It doesn't work.
Maybe because I didn't explained well.
This is project for a store. Table skladiste(=stock) is static. In there is list of all items (750 items) and now is empty. I need to fill it with data (amount) from 'order form' and 'receipt'. Data in these documents (tables kolicina(=amount), naziv_materijala(=name of item)) is dinamic. The 'id' in these tables isn't always the same and I can't use it to link tables.
I need to accomplish that data from 'order form' (a few (or more) items with certain amounts) put into table skladiste where one of rows is name of one item, and do it for each item and amount in order form.

Table skladiste look like:
id Naziv_materijala kolicina
1. Item_1
2. Item_2
...... ......
750 Item_750

Table kolicina look like and populating from order form:
id kolicina
1. 23
2. 45
3. 5
4. 7
5. 14

And table naziv_materijala look like and populating from order form:
id Naziv_materijala
1. Item_17
2. Item_6
3. Item_167
4. Item_333
5. Item_40

I don't know how to build a query with dinamic data, or with data from array.

I hope I have now explained better.

Still I feel you need your ID filed to link all the tables. You can export data from matrijal table to kolicina table like this.

Insert into skladiste select * from Naziv_materijala.

You can read more on copying data from here. This way you can take the records to your static table but to add the price you need to have links to update the matching records.
Please Login to post your reply or start a new topic