2016-07-06 2 views
-1

I "formid" hier in unter PHP-CodeWie Ergebnis der SQL-Abfrage zuzugreifen und sie in anderer SQL-Abfrage in PHP verwendet

<?php 

     header('Content-type=application/json;charset=utf-8'); 

     include("connection.php"); 
     session_start(); 

     if($_SERVER["REQUEST_METHOD"] == "POST") { 

     $event_date = mysqli_real_escape_string($con,$_POST['event_date']); 

     $event_location = mysqli_real_escape_string($con,$_POST['event_location']); 

     $organisation_name= mysqli_real_escape_string($con,$_POST['organisation_name']); 




     $query = "SELECT * FROM feedbackform_db WHERE event_date = '$event_date' and event_location = '$event_location' and organisation_name = '$organisation_name'"; 

     $response=mysqli_query($con,$query); 
     $rows = mysqli_num_rows($response); 


     if($rows == 0) { 
      $data['welcome'] = "unsucessful"; 
     } 
     else { 
      $row = mysqli_fetch_row($response); 
      $array = array(
       array(

        "formID"=>$row[0], 


       ) 
      ); 
      $data['welcome'] = "successful"; 
      $data['details'] = $array; 
      $data['success'] = 1; 
      $data['message']="successful"; 
      } 
      echo json_encode($data); 

    } 
    mysqli_close($con); 

    ?> 

ich eine in der gleichen PHP mehr INSERT SQL-Abfrage ausgeführt werden soll bin Abrufen Code, wo ich dieselbe FormID in eine andere Datenbanktabelle einfügen möchte Wie kann ich das tun?

+2

Versuchen Sie die erste Sache, die in den Sinn kommt. Ich wette, es wird funktionieren. – Solarflare

+0

Hat meine Antwort Ihnen geholfen? – Mcsky

Antwort

0

Nach der SELECT Abfrage ausgeführt werden.

$insertStr = "INSERT INTO othertable (someCol, rowId) VALUES (1, $row[0])"; 

$insertQry = mysqli_query($con, $insertStr); 

if ($insertQry) { 
    // What to do if the insert was successful 
} 
-1

Sie diese Methode verwenden, sollten als Array mysql Rückkehr Ergebnisse zu sagen, überprüfen Sie bitte http://php.net/manual/fr/mysqli-result.fetch-array.php

$array = []; 
while ($row = $result->mysqli_fetch_assoc()) { //Iterate on the rows returned by SQL 
    // $row is an array here 
    // I don't know your database model and relation between your 2 tables 
    // It isn't a good practice doing sql query while iterating 
    // For example with scalar values 
    $formId = $row['formID']; 
    $some = $row['some']; 
    $other = $row['other']; 
    $field = $row['field']; 
    $array[] = $row; 

    // Insert the line 
    $insertQuery = 'INSERT INTO yourothertable(formIdColumnOtherTable, some, other, field) VALUES($formId, $some, $other, $field)'; 
    $statement  = mysqli_prepare($insertQuery); 
    $successInsert = mysqli_stmt_execute($statement); 
} 
mysqli_close($con); 
... 
$data['details'] = $array; 
echo json_encode($data); 
exit; 

Für eine Antwort mehr angepasst mir bitte Ihre beiden Tabellen Definition

Ich gebe hoffe es hilft! :)

Verwandte Themen