Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Several questions regarding PHP and sql queries
Old 07-04-2006, 10:11 PM Several questions regarding PHP and sql queries
Junior Talker

Posts: 3
Trades: 0
I am very close to finishing my website which utilises PHP coupled with a MySQL database. However, I am at the stage where I only have a few very difficuly (in my opinion) things left to do.

I think I'll just ask the questions then post the code if it is needed.
  1. I have a member list, the details are taken from the member's table with a simple query. This works fine, however, I wish to add times from another table and put them into this member list as a total time.
Query that gets the simple information, name, id etc
Code:
  
// Request details of pilots
 $result = mysql_query("SELECT pid, first_name, last_name, vatsimid FROM roster");
  if (!$result) {
   echo("<P>Error performing query: " . mysql_error() . "</P>");
   exit();  }
Query that gets the times from the other table, subtracts them from each other to get total time, and only gets those times related to each member seperately:
Code:
// Select all the pireps the pilot has filed and add up the hours
   $sql = mysql_query("SELECT pirep.pid, roster.pid, SUM(pirep.arrtime-pirep.deptime) AS 'time' FROM pirep, roster WHERE pirep.pid = roster.pid GROUP BY pirep.pid");
  if (!$sql) {
   echo("<P>Error performing query: " . mysql_error() . "</P>");
   exit(); }
This doesn't work as it only gets the times for the first member and only displays that one member on the member list.

Page located here: http://southerncrossairlines.ausvirt...ete/roster.php

2. I have another form where the user types in start and finish times, and I want this to be inserted into the table in a format so I can use the above code to get a correct total time. Is there a way to do this and how?

3. On this same form, users select an id number, I want some text to appear next to this option list displaying the details of that id. How do I do this?
http://southerncrossairlines.ausvirt...lete/pirep.php

That's all the questions I have for now, I'll post again if I think of more.
Eskimo is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-06-2006, 04:53 AM Re: Several questions regarding PHP and sql queries
Junior Talker

Posts: 3
Trades: 0
Anyone?
Eskimo is offline
Reply With Quote
View Public Profile
 
Old 07-06-2006, 04:41 PM Re: Several questions regarding PHP and sql queries
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
... FROM roster LEFT JOIN pirep ON pirep.pid = roster.pid GROUP BY pirep.pid

should work I think
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-06-2006, 04:59 PM Re: Several questions regarding PHP and sql queries
Webmaster Talker

Posts: 626
Trades: 0
I'm not an expert with mysql by any means but here is where I would start:

I think your problems lye in the SUM() command, I think you are using it wrong. I understand the SUM() command to total a specific column within the table for example, lets say you had a table with the following columns:

-Customer
-PricePd

you could then use the SUM(PricePd) to determine what the TOTAL of all sales were... Try taking it out and seeing if it works...

Code:
$host = "localhost";
$user = "root";
$pw = "";

$link = mysql_connect($host, $user, $pw) or die(mysql_error());
$sql = "sELECT pirep.pid, roster.pid, pirep.arrtime, pirep.deptime AS 'time' FROM pirep, roster WHERE pirep.pid = roster.pid GROUP BY pirep;";

$result = mysql_query($sql, $link);

while($rows = mysql_fetch_array($result)) {
extract($rows);
$time = $arrtime - $deptime;
}
Not 100% sure if that is correct but you get the idea... You should be able to manipulate it using Chris's suggestion. Basically, extract the data from the database and manipulate it in PHP. It should be easier for you.

Last edited by jim.thornton; 07-06-2006 at 05:01 PM..
jim.thornton is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Several questions regarding PHP and sql queries
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19661 seconds with 12 queries