What is wrong with my PHP program? Can someone please help me! I am just a beginner…?
This what the outcome should be: The correct counts are 8 orders with multiple copies, 13 copies of Linux, 23 copies of Macintosh, and 16 copies of Windows.
I am not getting anything – just the print out code, but no numbers nothing. This is what i get:
SOFTWARE ORDERS: REPORT
ORDERS FOR MULTIPLE COPIES: 0
LINUX COPIES ORDERED: 0
MACINTOSH COPIES ORDERED: 0
WINDOWS COPIES ORDERED: 0
Plus, I don't know if i am doing it right….can someone please give me some sugestions on how to make it more efficient? thanx! this is my code:
<html>
<head>
<title>Software2</title>
<link rel ="stylesheet" type="text/css" href="sample.css" />
</head>
<body>
<?php
$multipleOrders = 0;
$linuxCopies = 0;
$macintoshCopies = 0;
$windowsCopies = 0;
$orderFile = fopen("orders.txt", "r");
$nextOrder = fgets ($orderFile);
while (!feof($orderFile))
{
if ($nextOrder > 1)
{
$multipleOrders = $multipleOrders + $nextOrder;
$multipleOrders = $multipleOrders + 1;
}
elseif ($nextOrder == $linux)
{
$totalCopies = $totalCopies + $linuxCopies;
$totalOrders = $totalOrders + 1;
$nextOrder = fgets($orderFile);
}
elseif ($nextOrder == $macintosh)
{
$totalCopies = $totalCopies + $macintoshCopies;
$totalOrders = $totalOrders + 1;
$nextOrder = fgets($orderFile);
}
else ($nextOrder == $windows)
$totalCopies = $totalCopies + $windowsCopies;
$totalOrders = $totalOrders + 1;
$nextOrder = fgets($orderFile);
}
list($os, $numCopies) = split (":", $nextOrder);
}
fclose ($orderFile);
//end while
print ("<h1>SOFTWARE ORDERS: REPORT</h1>");
print ("<p>ORDERS FOR MULTIPLE COPIES: $multipleOrders</p>");
print ("<p>LINUX COPIES ORDERED: $linuxCopies</p>");
print ("<p>MACINTOSH COPIES ORDERED: $macintoshCopies</p>");
print ("<p>WINDOWS COPIES ORDERED: $windowsCopies</p>");
?>
</body>
</html>
Thanx in advanced!
well, I can do:
elseif ($nextOrder == $linuxCopies)
elseif ($nextOrder == $macintoshCopies)
elseif ($nextOrder == $windowsCopies)
all the variables above have been define to cero and still don't work.
ok elven_rangers, but how can I fix it? could you give an idea? I am new with all this…
There are many problems:
$macintoshCopies,$linuxCopies, $windowsCopies never change their values. Where do these get their values? They start at 0 and don't change.
What do the lines in the file represent?
What values do the variables $linux, $macintosh, $windows have? If they're not initialized, then they are null and whatver $nextOrder is, the code inside the if's related to these three will never ever run.
In the first if, you overwrite the value for $multipleOrders twice, first it's itself plus nextOrder, then it's itself plus 1, why don't you make it a single line?
What is $nextOder supposed to be? I can tell you that if it's a string, then your code will never run so it's no surprise the values are all 0 in the end.
In the statements
elseif ($nextOrder == $linux)
elseif ($nextOrder == $windows )
elseif ($nextOrder == $macintosh)
What are the values of $linux, $windows and $macintosh.? I don't see them defined;
They're presumably numbers, but they need to be defined:
(Something like $linux=1; $windows=2; $macintosh=3;)
References :
There are many problems:
$macintoshCopies,$linuxCopies, $windowsCopies never change their values. Where do these get their values? They start at 0 and don't change.
What do the lines in the file represent?
What values do the variables $linux, $macintosh, $windows have? If they're not initialized, then they are null and whatver $nextOrder is, the code inside the if's related to these three will never ever run.
In the first if, you overwrite the value for $multipleOrders twice, first it's itself plus nextOrder, then it's itself plus 1, why don't you make it a single line?
What is $nextOder supposed to be? I can tell you that if it's a string, then your code will never run so it's no surprise the values are all 0 in the end.
References :