Hack Forums
[HTML | CSS | PHP] Help Desk | Need help with Homework Or Just stuck at something? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Webmasters (https://hackforums.net/forumdisplay.php?fid=141)
+---- Forum: Website Construction (https://hackforums.net/forumdisplay.php?fid=50)
+---- Thread: [HTML | CSS | PHP] Help Desk | Need help with Homework Or Just stuck at something? (/showthread.php?tid=4593580)

Pages: Pages 1 2


* - Glenndilen - Dec 28, 2014

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).


* - Isildur - Dec 28, 2014

(Dec 28, 2014 07:44 PM)Seagull 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);



* - Glenndilen - Dec 29, 2014

(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? šŸ˜…


* - Isildur - Dec 29, 2014

(Dec 29, 2014 03:36 AM)Seagull 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


* - noreply - Dec 29, 2014

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!


* - [[R9]] - Dec 31, 2014

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.


* - CatDogeā„¢ - Dec 31, 2014

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+phase+1+-+video.getUploadUrl

Here is a PHP example for the processing script: https://github.com/apiok/php_sdk_example/blob/master/example.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..


* - Isildur - Dec 31, 2014

(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+phase+1+-+video.getUploadUrl

Here is a PHP example for the processing script: https://github.com/apiok/php_sdk_example/blob/master/example.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/blob/master/example.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.


* - bmxican - Dec 31, 2014

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 !


* - CatDogeā„¢ - Jan 1, 2015

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?


* - Isildur - Jan 1, 2015

(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..


* - CatDogeā„¢ - Jan 1, 2015

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.


* - Isildur - Apr 14, 2015

(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