这是我的数据库 SQL 代码;
CREATE TABLE ProductType
(
ptID int not null auto_increment,
pType varchar(30),
PRIMARY KEY(ptID)
)ENGINE=InnoDB;
CREATE TABLE Service
(
sID int not null auto_increment,
description varchar(30) not null,
revenue int,
stID int not null,
PRIMARY KEY(sID),
FOREIGN KEY(stID) references ServiceType(stID)
)ENGINE=InnoDB;
CREATE TABLE Product
(
pID int not null auto_increment,
model varchar(30) not null,
cogs int,
ptID int not null,
PRIMARY KEY(pID),
FOREIGN KEY(ptID) references ProductType(ptID)
)ENGINE=InnoDB;
CREATE TABLE Sale
(
saleID int not null auto_increment,
assetID int not null,
eID int not null,
sID int not null,
pID int,
saDate date not null,
PRIMARY KEY(saleID),
FOREIGN KEY(eID) references Employee(eID),
FOREIGN KEY(sID) references Service(sID),
FOREIGN KEY(pID) references Product(pID)
)ENGINE=InnoDB;
CREATE TABLE Employee
(
eID int not null auto_increment,
firstName varchar(30) not null,
lastName varchar(30) not null,
phone varchar(30),
email varchar(30),
PRIMARY KEY(eID)
)
这是我的尝试,但当我查询“销售”表时,我不知道如何从“服务”访问“收入”字段。
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("pnl") or die(mysql_error());
// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM Sale WHERE saDate = CURDATE()")
or die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo "revenue: ".$row['revenue'];
?>
谁能给我一个例子,说明我将如何编写一个 php 脚本来检索当前日期所有销售的收入?
这也是我第一次尝试 SQL 和关系数据库模型,所以如果您发现我犯的任何严重错误或我可以改进的地方,请告诉我!