Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:05:24+00:00 2026-06-11T03:05:24+00:00

This is my database SQL code; CREATE TABLE ProductType ( ptID int not null

  • 0

This is my database SQL code;

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)
)

This is my attempt but I don’t know how to access the ‘revenue’ field from ‘Service’ when I am querying the ‘Sale’ table.

<?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'];

?>

Can anyone give me an example of how I would write a php script to retrieve the revenue of all sales for the current date?

Also this was my first attempt at SQL and relational database models, so if you notice any critical mistakes I’ve made or things I can improve please let me know!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:05:26+00:00Added an answer on June 11, 2026 at 3:05 am

    Try this way. Name the SUM field and access it by given name:

    // Retrieve all the data from the "example" table
    $result = mysql_query("SELECT SUM(Service.revenue) sum FROM Service JOIN Sale ON Sale.sID = Service.sID WHERE Sale.saDate = $some_date") 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['sum'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code extract is from database.sql file that comes with KohanaJobs app. CREATE TABLE
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
I have a mysql table like this (sql): CREATE TABLE IF NOT EXISTS silver_and_pgm
I create a table in SQL Server Management Studio with this code: CREATE TABLE
I have this code to update my SQL database from data in a textbox,
I have a table like this in my database (SQL Server 2008) ID Type
I have created my database by this sql query: (CREATE DATABASE + DBName +
I have developed a program (C#) which creates a SQL database using this code:
Suppose I have this database table (some sample code below) that stores the relationship
Can anyone alter this code to include one integer variable. Not including the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.