English 中文(简体)
MySQL PHP从表上向另一个表上提供
原标题:MySQL PHP id from on table to another
  • 时间:2012-05-18 22:45:33
  •  标签:
  • php
  • mysql

我建造了一个从检查箱获取信息的阵列。 但是,如果将第二张表格的复制件放在阵列数据旁,则需要第二份投入。 例如,当用户对我的实验室格式的投入数据时,它就在一张桌上产生一种id,而我的检查箱则被保存到另一个桌上。 我想,当用户选择检查箱时,该盒子被放在这里。 问题一是,我只想知道如何提供这一数据。

$insertSQL2 = "INSERT INTO Project_course (Proj_id Cour_id) SELECT Course_id FROM courses WHERE 
Code IN (";
foreach ($_POST[ CheckboxGroup1 ] as $Q){
$Q = mysql_real_escape_string($Q);
$insertSQL2.= " $Q , ";
 } 
 $insertSQL2 = rtrim($insertSQL2, ", ");
$insertSQL2 .= ")";

Proj_id是需要去做的地方,而Cun_id则是可节省检查箱的地方。 随着这种情况的恶化,需要同时进行,因为在我的桌上的关系意味着一栏不能落空。

我很早就知道这一点,因此任何帮助都会得到感激的接受。

最佳回答

如果我正确理解你的问题,形式首先可以节省项目数据,然后是该项目的一些课程数据。

BTW——我建议的第一件事是,将纯粹的我sql_*职能留给发展办公室。 但这并非偶然。

任何方面——首先,你可能掌握着类似的东西。

$sql = "INSERT INTO project (col1, col2) VALUES (blah1, blah2)";
mysql_query($sql)

Then you can check the new project ID simply by invoking

$projectID =  mysql_insert_id();

之后,情况就是如此。

foreach ($_POST[ CheckboxGroup1 ] as $key => $val)
{
    $_POST[ CheckboxGroup1 ][$key] =  mysql_real_escape_string($val);
}
$sql = "INSERT INTO project_course(project_id, course_id) SELECT ".$projectID.", course_id FROM courses WHERE code IN (".implode(", ", $_POST[ CheckboxGroup1 ]).")";

UPDATE——如果你在项目桌上已经有一个项目,你可以以几种方式获得项目身份证。 例如,利用<代码>SlectT项目_id DESC LIMIT 1

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...