Jump to content

Insert into .. select


Pete666
Go to solution Solved by Barand,

Recommended Posts

I'm trying to insert rows from staffonblock table into the same staffonblock table.

The new rows will have the same groupid and staffid as the selected rows but the newblockid and newblocksetid will be as provided by the variables.

I'm calling the php file from a jQuery script using ajax and sending in the 4 variables but the  ajax call returns an error, PHPMyadmin says the syntax of the php file is ok.

Here is staffonblock table before the required insert:

g1, s1, 1, 1

g1, s2, 1, 1

.. and eg what is required after insert:

g1, s1, 1, 1

g1, s2, 1, 1

g1, s1, 2, 2

g1, s2, 2, 2

help appreciated.

<?php

include_once ('tl2_connect.php'); $instance = ConnectDb::getInstance(); $conn = $instance->getConnection();

$groupid       = $_POST["groupid"];
$blockid       = $_POST["blockid"];

$newblockid       = $_POST["newblockid"];
$newblocksetid    = $_POST["newblocksetid"];


$sql = "INSERT INTO staffonblock (groupid, staffid, blockid, blocksetid) 
                   
        SELECT groupid, staffid, ".$newblockid."', '".$newblocksetid."' FROM staffonblock 
    
        WHERE blockid='".$blockid."'  AND groupid='".$groupid."';" ;

$conn->exec($sql)        

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.