【发布时间】:2019-08-31 19:09:09
【问题描述】:
我正在开发一个管理学校教师的 php 项目。但我遇到了一个问题,我的数据库中有两个表,第一个 T1 在行上,第二个 T2 有多行,但它们的列号相同。在第三个表 T3 中,我需要用总计填充一列 (T1 的单元格1*T2 的单元格1) + (T1 的单元格2*T2 的单元格2)+ (T1 的单元格3*T2 的单元格3)....到最后一列 我只是找不到正确的方法来做到这一点
这是显示我的数据库中的表的部分
<?php
$host="localhost";
$user="root";
$pass="";
$bdd="test";
$cnx=mysql_connect($host,$user,$pass);
if(!$cnx)
echo"connexion echouee"."</br>";
else
echo"connexion reussie"."</br>";
if (mysql_select_db($bdd))
echo"base de donnees trouvee"."</br>";
else
echo"base de donnees introuvable"."</br>";
$req1="SELECT * FROM `table1`";
$res1=mysql_query("$req1");
// printing table rows
while($row1 = mysql_fetch_row($res1))
{
echo "<tr>";
foreach($row1 as $cell1)
echo "<td>|$cell1|</td>";
echo "</tr>"; echo"</br>";
}
echo "_____</br>";
$req2="SELECT * FROM `table2`";
$res2=mysql_query("$req2");
// printing table rows
while($row2 = mysql_fetch_row($res2))
{
echo "<tr>";
foreach($row2 as $cell2)
echo "<td>|$cell2|</td>";
echo "</tr>";echo"</br>";
}
?>
【问题讨论】:
-
分享你的代码吗?
-
那么你打算通过 PHP 还是 MySQL 来实现呢?
-
我打算使用php,但我需要mysql来获取表格的内容
-
值得注意的是,
mysql_*系列函数不再存在于任何受支持的 PHP 版本中。您可能应该使用PDO或至少mysqli。任何使用mysql_connect的教程都已经过时了。
标签: php mysql calculation