www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] Creating Temporary tables for Basket

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    27

    resolved [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.

  2. #2
    Join Date
    Jan 2014
    Posts
    27

    Create Temp table:Getting Errors HELPP!!!

    PHP Code:
    <?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;
    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

  3. #3
    Join Date
    Dec 2013
    Posts
    63
    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.
    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.

  4. #4
    Join Date
    Jan 2014
    Posts
    27
    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;
    ?>
    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

  5. #5
    Join Date
    Dec 2013
    Posts
    63
    Hi. You've mixed mysql_ and mysqli_ functions! If you use mysqli_query you should use mysqli_connect. But I've never used mysqli, so I may be wrong.

  6. #6
    Join Date
    Jan 2014
    Posts
    27
    Yh, I realised that. Thanks for the help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles