PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 14th, 2004, 04:58 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Problem pulling data from tables

Here I am again. Its hard not to come back again because most of the time you get some great help in this forum. So you will have to excuse my new request for an assist. I have been spending a lot of time reviewing some of the online tutorials in an attempt to gain a better handle on working with Php. My most recent excursion is trying to modify this script I got from one of the tutorials to put together a simple timekeeping and reporting database. Now I am stuck again! The problem seems to be with accessing my database. The scripts appear to run in my IDE interface (Maguma Studio's) but don't pull the information from my tables i.e. client and billing. I have changed the connection string to the correct machine, user and password but my select and insert queries in the scripts (below) don't seem to do anything. I am too incompetent at this stuff to find an error in the Php code, or perhaps I have just starred at it too long! If anyone can steer me in the right direction I would be immensely appreciative! Below is my table structure and the two scripts.
Thanking You in Advance!






CREATE TABLE client (
client varchar(100) NOT NULL,
id int AUTO_INCREMENT NOT NULL,
PRIMARY KEY (id)
);


CREATE TABLE billing (
client int(11) NOT NULL,
employee varchar(100) NOT NULL,
job_type varchar(100) NOT NULL,
time_spent int(11) NOT NULL,
wage int(11) NOT NULL,
billable int(11) NOT NULL,
description longtext NOT NULL,
id int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
);

/////////////////////////////////////////////////////////////////
billing.php




/* the billing.php script */

<?php
$db = mysql_connect ("localhost", "root", "");
mysql_select_db ("nhla_cases", $db);

if ($submit) {
if ($clientsubmit) {
$sql = "
INSERT INTO client (client)
VALUES ('$newclient')
";
$result = mysql_query($sql);
} else if ($submitbill) {
$sql = "
INSERT INTO billing (employee, client, job_type, time_spent, billable, description, wage)
VALUES ('$employee', '$client', '$jobtype', '$timespent', '$billable', '$desc', '$wage')
";
$result = mysql_query($sql);

echo "Thank you for your entry, <a href='billing.php?employee=$employee'>click here</a> to enter another.</a>";
exit;
}
?>
<form method="POST" action="billing.php">
<table>
<tr>
<td>Client</td>
<td>Job Type</td>
<td>Time Spent (hrs)</td>
<td>Wage</td>
<td>Billable</td>
<td>Description</td>
</tr>
<tr>
<td>
<select name="client">
<?php

$sql = "
SELECT id, client
FROM client
";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result))
{
$client = $row["client"];
$id = $row["id"];
echo "<option value='$id'>$client</option>";
}
?>
</select>
</td>
<td>
<select name="jobtype">
<option value="Support">Technical Support</option>
<option value="Programming">Programming</option>
<option value="Accounting">Accounting</option>
<option value="Consulting">Consultation</option>
</select>
</td>
<td>
<input type="text" name="timespent" size="4">
</td>
<td>
<select name="wage">
<option value="20">$20 x hr</option>
<option value="40">$40 x hr</option>
<option value="60">$60 x hr</option>
<option value="80">$80 x hr</option>
<option value="100">$100 x hr</option>
</select>
</td>
<td>
<select name="billable">
<option value="1">Yes</option>
<option value="2">No</option>
</select>
</td>
<td>
<textarea name="desc"></textarea>
</td>
</tr>
<tr>
<td colspan="5">
<input type="hidden" name="employee" value="<?php echo $employee;?>">
<input type="hidden" name="submit" value="1">
<input type="submit" name="submitbill" value="Submit Billing">
</td>
</tr>
</table>
</form>
<br><br>
<hr>
<form method="POST" action="billing.php">
Add new client: <input type="text" name="newclient">
<input type="hidden" name="employee" value="<?php echo $employee;?>">
<input type="hidden" name="submit" value="1">
<input type="submit" name="clientsubmit" value="Submit New Client">
</form>

<?
} /* End of if ($submit) */
else
{
$employees = array ("Patrick", "Avi", "Sara", "Jessica", "Tasha", "Vegi");

$j = count ($employees);
?>
<form method='POST' action='billing.php'>
<select name='employee'>
<?php
for ($i = 0; $i < $j; $i++) {
echo "<option value='{$employees[$i]}'>{$employees[$i]}</option>";
}
?>
</select>
<input type='submit' name='submit'>
</form>
<?php
}
?>

//////////////////////////////////////////////
report.php

/* here begins the report.php script */

<?php
$db = mysql_connect ("localhost", "root", "");
mysql_select_db ("nhla_cases", $db);

if ($submit) {
?>
<table>
<tr>
<td>Employee</td>
<td>Client worked for</td>
<td>Job Type</td>
<td>Time Spent(hrs)</td>
<td>Amount Billed</td>
<td>Billable</td>
<td>Description</td>
</tr>
<tr>
<td colspan='7'>
<hr>
</td>
</tr>
<?php
$j = count ($worker);
for ($i = 0; $i < $j; $i++)
{
$employee = $worker[$i];
$sql = "
SELECT billing.*, client.*
FROM billing, client
WHERE employee = '$employee' AND billing.client = client.id
";
$result = mysql_query($sql);

if (!mysql_num_rows($result)) {
echo "<tr><td>I'm sorry, but there is no information for $employee.</td></tr>";
}

while ($row = mysql_fetch_array($result)) {
$client = $row["client"];
$jobtype = $row["job_type"];
$employee = $row["employee"];
$desc = $row["description"];
$billable = $row["billable"];
$timespent = $row["time_spent"];
$wage = $timespent * $row["wage"];

if ($billable == "1") {
$billable = "Yes";
}

echo "<tr>";
echo "<td>$employee</td>";
echo "<td>$client</td>";
echo "<td>$jobtype</td>";
echo "<td>$timespent</td>";
echo "<td>$$wage</td>";
echo "<td>$billable</td>";
echo "<td>$desc</td>";
echo "</tr>";
}

$sql2 = "
SELECT SUM(time_spent * wage) AS totalwage,
SUM(time_spent) AS totaltime
FROM billing
WHERE employee = '$employee'
";
$result2 = mysql_query($sql2);

while ($row2 = mysql_fetch_array($result2)) {
$totalwage = $row2["totalwage"];
$totaltime = $row2["totaltime"];
?>
<tr>
<td colspan='7'>&nbsp;</td>
</tr>
<tr>
<td>Total Time Spent: <?php echo $totaltime; ?> hours</td>
<td>Total Wages Billed: $$totalwage</td>
</tr>
<tr>
<td colspan='7'><hr noshade></td>
</tr>
<?php
}
}
?>
</table>
<?php
} /* end of if($submit) */
else
{
$employees = array ("Patrick", "Avi", "Sara", "Jessica", "Tasha", "Vegi");
?>
<form method='POST' action='report.php'>
<table>
<?php
$j = count ($employees);

for ($i = 0; $i < $j; $i++) {
?>
<tr>
<td><?php echo $employees[$i]; ?>:</td>
<td>
<input type='checkbox' name='worker[]' value='<?php echo $employees[$i]; ?>'>
</td>
</tr>
<?php
}
?>
</table>
<input type='submit' name='submit' value='Run Report'>
</form>
<?php
}
?>

Reply With Quote
  #2  
Old June 16th, 2004, 03:24 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
I figured it out

Its remarkable what a good nights sleep will do to one's concentration.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Problem pulling data from tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT