0

好的,所以我有 3 张桌子

1.phone: id name 制造商id osid

2.manufacturermanufacturerid制造商名称

3.os osid osname

每次我想上传第一个表时,我如何将其中一个表(manufacturerid1 ->manufacturid2 和 osid1>osid2)中的数据放到第一个表中...

我什至不确定我问的问题是否正确,我只想为制造商制作一张表格,因此当我显示制造商名称时,我单击其中一个名称,然后出现属于该制造商/操作系统的每部电话.

另外,我如何通过 php 更新数据(我的完整电话表更长,而我不需要更多表来使用的数据)

这是我在意识到我需要制造商(品牌)和操作系统(操作系统)表之前使用的脚本,因此当我通过其中一个显示它们时,不会弹出更多同名制造商。

 <?php
 include 'connect.php';
 mysql_select_db("phone", $connect);


 $id = $_POST['ID'];
 $name = $_POST['name'];
 $stock = $_POST['stock'];
 $brand = $_POST['brand'];
 $operatingsystem = $_POST['operatingsystem'];
 $camera = $_POST['camera'];
 $handset = $_POST['handset'];
 $screen = $_POST['screen'];
 $connectivity = $_POST['connectivity'];
 $batterylife = $_POST['batterylife'];
 $memory = $_POST['memory'];
 $messaging = $_POST['messaging'];
 $soundformat = $_POST['soundformat'];
 $price = $_POST['price'];
 $flag= $_POST['flag'];

 $sql = "UPDATE phone SET name='$name', stock='$stock', brand='$brand',   operatingsystem='$operatingsystem', camera='$camera', handset='$handset', screen='$screen', connectivity='$connectivity', batterylife='$batterylife', memory='$memory', messaging='$messaging', soundformat='$soundformat', price='$price', flag='$flag' WHERE ID='$id' ";


 if (!mysql_query($sql,$connect))
 {
 die('Error: ' . mysql_error());
 }
 echo "<h1>1 record was just updated in the database.</h1>";

 mysql_close($con);

 ?>      
4

1 回答 1

0

"I'm not even sure im asking the right question, all i want is to make a table for a manufacturer so when i display the manufacturer names, i click on one of the names and every phone that belongs to that manufacturer/os shows up."

In that case to make things easy on yourself, have one table called phones, one table called manufacturer and one table that links the phone to the manufacturer (and possibly another table for O/S ?)

Manufacturer table:
manufacturerID
name
otherData
moreData

Phone table:
phoneID
name
phoneData

OS Table:
osID
name
osData

Link Table:
phoneID
osID
manufacturerID

Perform all of your searches on the link table, then simply retrieve the information you want from the other tables.

于 2013-02-07T03:16:14.297 回答