/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Creating Temporary tables for Basket

Hello Everyone,

I have to create a temporary table for basket. I have to include certain fields from different table.

Now I know the code to create a temporary table “CREATE TEMPORARY TABLE temp”, is that right?

But I dont know how to choose different fields from different table.

Thank You.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@mfredy92authorJan 03.2014 — [code=php]<?php
$hostname = "localhost";
$username = "1104107";
$password = "r940c1";
$database = "db1104107";
//echo '24';

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password);
$db = mysql_select_db($database, $dbhandle)
or die("Unable to connect to MySQL");
//echo "Connected to MySQL<br>";

$query_createTemporaryTable = "CREATE TEMPORARY TABLE temp(temp_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
ArtistName VARCHAR(20), NAME of the DVD VARCHAR(30)";

$result_createtemptable = mysqli_query($dbhandle, $query_createTemporaryTable);

$query_insertintotable = "INSERT INTO everything (ArtistName, NAME of the DVD) VALUES ('RIHANNA', 'SHAWSHANK')";

$result_insertintotable = mysqli_query($dbhandle, $query_insertintotable);

$query_selecttemptable = "SELECT ArtistName,NAME of the DVD FROM temp";

$result_selecttemptable = mysqli_query($dbhandle, $query_selecttemptable);

$row_selecttemptable = mysqli_fetch_array($result_selecttemptable);

echo $row_selecttemptable;[/code]


Errors:


Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /studhome/0/1104107/public_html/mysql_connect.php on line 19

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /studhome/0/1104107/public_html/mysql_connect.php on line 23

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /studhome/0/1104107/public_html/mysql_connect.php on line 27

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /studhome/0/1104107/public_html/mysql_connect.php on line 29
Copy linkTweet thisAlerts:
@blasphemyJan 03.2014 — Hi. You create temporary table just like other 'normal' tables. The difference is 'temporary' keyword and the fact that:

A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed. This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.) To create temporary tables, you must have the CREATE TEMPORARY TABLES privilege.[/quote]

Above words are taken from MySQL documentation.

So, you can create it with normal CREATE TABLE statement (with TEMPORARY keyword) with column definition, and then you can insert data into it using SELECT queries.
Copy linkTweet thisAlerts:
@mfredy92authorJan 03.2014 — Can you tell me if I am on the right lines. I am gettin some errors

<?php

$hostname = "localhost";

$username = "1104107";

$password = "r940c1";

$database = "db1104107";

//echo '24';

//connection to the database

$dbhandle = mysql_connect($hostname, $username, $password);

$db = mysql_select_db($database, $dbhandle)

or die("Unable to connect to MySQL");

//echo "Connected to MySQL<br>";

$query_createTemporaryTable = "CREATE TEMPORARY TABLE temp(temp_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,

ArtistName VARCHAR(20), NAME of the DVD VARCHAR(30)";

$result_createtemptable = mysqli_query($dbhandle, $query_createTemporaryTable);

$query_insertintotable = "INSERT INTO everything (ArtistName, NAME of the DVD) VALUES ('RIHANNA', 'SHAWSHANK')";

$result_insertintotable = mysqli_query($dbhandle, $query_insertintotable);

$query_selecttemptable = "SELECT ArtistName,NAME of the DVD FROM temp";

$result_selecttemptable = mysqli_query($dbhandle, $query_selecttemptable);

$row_selecttemptable = mysqli_fetch_array($result_selecttemptable);

echo $row_selecttemptable;

?>[/QUOTE]


these are the errors I am getting.

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /studhome/0/1104107/public_html/mysql_connect.php on line 19

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /studhome/0/1104107/public_html/mysql_connect.php on line 23

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /studhome/0/1104107/public_html/mysql_connect.php on line 27

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /studhome/0/1104107/public_html/mysql_connect.php on line 29
Copy linkTweet thisAlerts:
@blasphemyJan 03.2014 — Hi. You've mixed mysql_ and mysqli_ functions! If you use mysqli_query you should use [url="http://php.net/manual/pl/function.mysqli-connect.php"]mysqli_connect[/url]. But I've never used mysqli, so I may be wrong.
Copy linkTweet thisAlerts:
@mfredy92authorJan 03.2014 — Yh, I realised that. Thanks for the help
×

Success!

Help @mfredy92 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...