What I'm trying to achieve is simple.
I would like to insert all my products into one table, and then insert all my prices into another table, while keeping track of the ID for each product, so that I can then insert them into the "id" field of the prices (which is not a primary key).
(Dec 28, 2014 07:44 PM)Glenndilen Wrote: What I'm trying to achieve is simple.
I would like to insert all my products into one table, and then insert all my prices into another table, while keeping track of the ID for each product, so that I can then insert them into the "id" field of the prices (which is not a primary key).
Assuming you are using php.
$query1 = "INSERT INTO ..... ";
$YourDBDriver->query( $query1 );
If you use mysql. Then, you can fetch the last inserted id (Primary key) by:
$id = mysql_insert_id();
Different drivers use different methods. When using PDO, lastInsertId() method can be used.
and then use this with the second query
$query2 = "INSERT INTO `Table` ( primaryid, id, OTHERFIELDS ) VALUES ( NULL, {$id}, OTHERFIELDS )";
$YourDBDriver->query( $query2 );
The same can also be achieved using SQL only, inwhich you need to execute multiple queries at the same time.
For this you need to use the CLIENT_MULTI_STATEMENTS constant (orr numeric value 65536) in your mysql connect function.
Then you can just use:
Code INSERT INTO Tablename ( some_fields ) VALUES ( some_values );
SET @last_id = LAST_INSERT_ID();
INSERT INTO Othertable ( id, some_fields ) VALUES (@last_id, some_fields);
Web Developer | Game Developer
Got MyBB? Contact me for Theme Creation Or Plugin Development
(Dec 28, 2014 11:22 PM)Isildur Wrote: Assuming you are using php.
$query1 = "INSERT INTO ..... ";
$YourDBDriver->query( $query1 );
If you use mysql. Then, you can fetch the last inserted id (Primary key) by:
$id = mysql_insert_id();
Different drivers use different methods. When using PDO, lastInsertId() method can be used.
and then use this with the second query
$query2 = "INSERT INTO `Table` ( primaryid, id, OTHERFIELDS ) VALUES ( NULL, {$id}, OTHERFIELDS )";
$YourDBDriver->query( $query2 );
The same can also be achieved using SQL only, inwhich you need to execute multiple queries at the same time.
For this you need to use the CLIENT_MULTI_STATEMENTS constant (orr numeric value 65536) in your mysql connect function.
Then you can just use:
Code INSERT INTO Tablename ( some_fields ) VALUES ( some_values );
SET @last_id = LAST_INSERT_ID();
INSERT INTO Othertable ( id, some_fields ) VALUES (@last_id, some_fields);
Yes, that would be the correct answer - except I can't hammer away at the database with individual SQL queries when entering thousands of products.
Can anyone help? 😅
(Dec 29, 2014 03:36 AM)Glenndilen Wrote: Yes, that would be the correct answer - except I can't hammer away at the database with individual SQL queries when entering thousands of products.
Can anyone help? 😅
Well that cant be helped :) If you have thousands of products, then you gotta do this all the time.
There will be 3 queries always, with each insert.
It is possible to insert multiple values with just on query, instead of 100 inserts, you can have just 1 query putting those 100 values.
But what you are trying to achieve is only possible via 3 queries per product. Since you need insert id.
A simple work around would be to insert the IDs in both tables manually. First perform query to insert 100 values in a table, whose IDs differ by 1, i.e 1,2,3,4.... 100
Then insert in second table, using the same sequence, 1,2,3...100
Web Developer | Game Developer
Got MyBB? Contact me for Theme Creation Or Plugin Development
I recently created a html5 index and I'm using IP.Board as a forum. The things i want to achieve:
- I want to use the same header and footer from my index on my forum as well.
- I want to use the same BG for both my index and forum
- I want to make the forum width a little bit narrower
I know it are only tiny changes i've summed up above but since i'm pretty inexperienced a little help will be much appreciated!
Okay I have tried at places but never reached to any conclusion.
I need a website or an application whatever that would help in video conferencing, audio conferencing etc.
Guide me. I need it for a college project.
I want to build a script where I can upload a video to ok.ru (website).
They use the Rest API and they have a documentation: http://apiok.ru/wiki/display/api/Upload+...tUploadUrl
Here is a PHP example for the processing script: https://github.com/apiok/php_sdk_example...xample.php
Here is a HTML Script for uploading:
PHP Code
<?php <form method="POST" enctype="multipart/form-data" action="upload.php"> <input type="file" name="v1" accept="video/*" /> <input type="submit" /> </form>
How can I upload videos through this API? I don´t get it..
Dec 31, 2014 10:25 PM
(This post was last modified: Dec 31, 2014 10:37 PM by Isildur.)
(Dec 31, 2014 02:25 PM)CatDoge™ Wrote: I want to build a script where I can upload a video to ok.ru (website).
They use the Rest API and they have a documentation: http://apiok.ru/wiki/display/api/Upload+...tUploadUrl
Here is a PHP example for the processing script: https://github.com/apiok/php_sdk_example...xample.php
Here is a HTML Script for uploading:
PHP Code
<?php <form method="POST" enctype="multipart/form-data" action="upload.php"> <input type="file" name="v1" accept="video/*" /> <input type="submit" /> </form>
How can I upload videos through this API? I don´t get it..
I checked it.
I am assuming that you are using this script: https://github.com/apiok/php_sdk_example...xample.php
Then, as the manual explains, you need to make a video.getUploadUrl request to the server, to get video url & id.
As you can see in the example script, requests are made using: OdnoklassnikiSDK::makeRequest("video.getUploadUrl");
The server will return an XML or JSON response, depending on the content type header you send it.
Extract the data from (parse XML, or parse JSON, i guess you can do that?)
<form method="POST" enctype="multipart/form-data" action="<upload URL>">
<input type="file" name="v1" accept="video/*" />
<input type="submit" />
</form>
Replace <upload URL> with the upload url extracted from the data....
Then, as the docs state, make another request "video.update" and done :)
(Dec 31, 2014 12:30 PM)[[R9]] Wrote: Okay I have tried at places but never reached to any conclusion.
I need a website or an application whatever that would help in video conferencing, audio conferencing etc.
Guide me. I need it for a college project.
Try https://github.com/lavaeagle/Simple-Webcam-Stream-PHP/
Reply with any errors you encounter.
(Dec 29, 2014 04:19 PM)noreply Wrote: I recently created a html5 index and I'm using IP.Board as a forum. The things i want to achieve:
- I want to use the same header and footer from my index on my forum as well.
- I want to use the same BG for both my index and forum
- I want to make the forum width a little bit narrower
I know it are only tiny changes i've summed up above but since i'm pretty inexperienced a little help will be much appreciated!
Hmm, you can either do one of the two things:
-> Copy paste html of header and footer in your .html page. But this would make it, you know, like a normal page. Your users, if logged in the board, wont be able to see themselves as logged in on your page, simply becuase it is an html page.
-> Get an addon. Easy Pages OR Ip.Content will solve your problems :) Both support Custom pages.
Web Developer | Game Developer
Got MyBB? Contact me for Theme Creation Or Plugin Development
DO NOT DEAL WITH THIS MEMBER
Dec 31, 2014 11:44 PM
(This post was last modified: Jan 1, 2015 12:17 AM by bmxican.)
Hey mate; anychance you could help me with switching hosting ? I have no idea what I am doing
Thanks heaps for your help mate ! quick answers !
First: Thanks a lot!!
Second: I am testing this at the moment:
PHP Code
<?php $video = OdnoklassnikiSDK::makeRequest("video.getUploadUrl"); var_dump($video);
But I get this error message:
Quote:array(3) { ["error_msg"]=> string(77) "PERMISSION_DENIED : User must grant an access to permission 'VALUABLE_ACCESS'" ["error_code"]=> int(10) ["error_data"]=> string(15) "valuable_access" }
What can I do?
(Jan 1, 2015 05:31 AM)CatDoge™ Wrote: First: Thanks a lot!!
Second: I am testing this at the moment:
PHP Code
<?php $video = OdnoklassnikiSDK::makeRequest("video.getUploadUrl"); var_dump($video);
But I get this error message:
What can I do?
In your account over there, look for any permission related settings.
There should be something to allow your application, etc..
Web Developer | Game Developer
Got MyBB? Contact me for Theme Creation Or Plugin Development
Seems not to be my fault, needed to contact support because its stated in the docs^^
Thanks, will reply as soon as I got everything working.
(Jan 1, 2015 06:34 AM)CatDoge™ Wrote: Seems not to be my fault, needed to contact support because its stated in the docs^^
Thanks, will reply as soon as I got everything working.
Oh okay.
I will resume the help desk work now :D
Web Developer | Game Developer
Got MyBB? Contact me for Theme Creation Or Plugin Development
|