TABLE1: table1ID | studentnum | lname | fname | mname
TABLE2: table2ID | studentnum | remarks | others
//THIS IS MY FORM 1
$sql = "INSERT INTO TABLE1 (studentnum, lname, fname, mname)
VALUES ('$studentnum','$lname','$fname','$mname')";
$sql1 = $sql = "INSERT INTO TABLE2 (studentnum)
VALUES ('$studentnum')";
mysql_select_db('databasename');
$retval = mysql_query($sql);
if(!$retval ) {
die('Could not enter data: ' . mysql_error());
}
$retval = mysql_query($sql1);
if(!$retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Data added successfully!";
mysql_close($conn);
SAMPLE OUTPUT:
TABLE1:
table1ID | studentnum | lname | fname | mname
1 | 1001 | My | An | Swer
TABLE2:
table2ID | studentnum | remarks | others
1 | 1001 | |
表 2 现在包含表 1 中的学生编号编码数据。 我想要这个输出,我怎样才能从 FORM 2 做到这一点
//sample output with form1 and form2 values
table2ID | studentnum | remarks | others
1 | 1001 | good | N/A
我有 2 张表格和 2 张表格,请参阅上面的代码。任何人都可以帮助我如何做到这一点?
检查你从数据库中得到的值,当它们为空时,你可以使用 php empty(( 函数用一些东西替换这些值来保持它们的位置(好或 N/A(。
请参阅此页面。
此外,如果所需的所有信息都不在 TABLE2 中,请考虑使用 SQL 联接。