Php program, PHP Web Programming

Assignment Help:

You have a new file to work with:  bobsinventory.php.  The great news is that this file contains a single string variable with every piece of data from the inventory table you first encountered in Program #3, but also two more pieces of data.  So, now you won't be burdened with the need to create dozens of variables and initialize them to table values.  The whole table and more is in the file!

As suggested above, the days rented value for each vehicle has been updated with the correct number.  The names of the vehicles have been abbreviated somewhat, and now there are no spaces in any of the individual data.  Further, there are two more "fields" of data:  the actual revenue generated so far by each vehicle and the mileage for each one.  Someone told Bob that if he doesn't track the mileage, then using the depreciation factor alone might raise eyebrows in certain federal units!

So, just to summarize, the file now contains details on each vehicle in this order:  vehicle name; model year; serial number; #seats; rental charge per day; days rented so far this year; total revenue for this vehicle so far; original price of vehicle; mileage on the vehicle; depreciation factor; and scheduled maintenance interval.  (With all this data available, it's almost as if we got these numbers out of a database! J)

Of course, now the challenge becomes that of getting the data into appropriate variables to use. Actually, I should say into an appropriate array, because as you surely must anticipate, that's what this program is going to be about.  One by one you will need to read each vehicle's data into an associative array.  I will cover some specifics in just a moment.

NOTE.  There are many different ways to go about achieving the goals of any programming project.  There are almost always multiple ways of accomplishing the same thing with different coding structures.  But what this program will require are two mandatory concepts:  #1, use an associative array; and #2, successfully use a foreach loop.  Your processing must consist of a similar while loop to what you used in Program #5:  a while loop predicated on there still being data to take out of the string with strtok.  Only this time, instead of grabbing the values and placing them into separate variables, you must use an associative array to hold all eleven pieces of data for one vehicle.  You are to use only one array to hold vehicle data:  you are not allowed to use a separate array for each vehicle!  Therefore, you will need to grab the data for each vehicle one set of data at a time.

Let's say you decide to use an array called $vehicle.  Make up string names for each of the eleven keys you will need for the array.  For example, you might use 'name' for the vehicle's name.  Loading the array elements is no different from loading the data into a "normal" variable:  you just need to use the correct array element on the left side of the assignment (with the correct key).  For example, to get the first set of values, I would probably start pulling them out this way:

$vehicle['name'] = rtrim(strtok($rental_data, " "));

$vehicle['year'] = rtrim(strtok(" "));

$vehicle['serial']  = rtrim(strtok(" "));

And so on.  The first 10 values for each vehicle are terminated by spaces and the last value by a carriage return.

(Remember that after the very first call to strtok, you can't use the variable name again, or else the strtok function will start all over again at the beginning of the entries.)  So, now after you have grabbed the first set of vehicle data, the element $vehicle['name'] will have the value 'DodgeAvenger' in it.  Continuing, $vehicle['year'] will have the value 2006 in it, etc.

After getting all of the first vehicle's eleven values into the array, now start up your while loop.  You can just use the array's first element as the condition, since if the value $vehicle['name'] is defined, then there is more work to do.

Inside the while loop is the time you need to process the array.  That gets us to my next mandatory requirement.  You must use a foreach loop to loop through all the elements of the array $vehicle.  Your first requirement inside the loop will be to display some data for each vehicle in columns.  For that purpose you are not allowed to simply use the array values directly, for example, printing $vehicle['name'] and $vehicle['year'], etc.  That would be much too easy, and you wouldn't be learning anything about the foreach loop.

So, inside your while loop, start a foreach loop.  As I illustrated in my Addendum to this chapter, the foreach syntax "breaks down" the loop elements into two simple variables, often called $key and $value.  If you follow the naming system I use in the Addendum, then the first $key will be 'name' and the first $value will be 'DodgeAvenger'.  The next time through the foreach loop, $key will be 'year' and $value will be 2006.  So, each time through your foreach loop the variables $key and $value become the next key/value pair for the current vehicle.

(At this point you might be thinking:  this is surely a clunky way to deal with the car data.  Why not just use the array data directly?  The answer is that I want you to learn as much about the foreach loop as possible.  So, I want to force you to work with the data broken down inside the foreach loop to really master that tool.)

Here's what I want you to perform inside the foreach loop.  Display a one-line listing of some of the data for the vehicle.  Show data for each vehicle in the following order.  (These are example headers for each column.)

VEHICLE YEAR SERIAL# RENTALCOST DAYSOUT REVENUE ORIGPRICE MILEAGE NOTES   

The VEHICLE through MILEAGE values come right from your data values.  But note that you are not to display the values for Seats, Depreciation Factor, and Maintenance Interval.  As you encounter these values in the foreach loop, you need to skip printing them.  (Hint:  you'll need to test to see if the $key is equal to any of these.)

So, just to make this as clear as I can.  Inside the foreach loop, you will have displayed the VEHICLE, YEAR, etc all the way to the MILEAGE values for one vehicle.  The total amount of code required to do this should not be more than two to three lines, not including the start of the loop, the foreach header.  I am not looking for a beautifully composed set of incredibly spaced and formatted columns.  I am looking for whether or not you understand how to use the keys and values as they are parsed from the array.

Now, after the foreach loop has displayed almost one complete line, there are a few more details to attend to.  The NOTES column is not yet composed.  Here's the kind of notes that you need to display.  For any vehicle that has over 100,000 miles, display the letter 'I' in that column, a flag that this vehicle needs to be Inspected more often.  Also, for any vehicle that has fewer than 10 days actually rented, place an 'L' in the NOTES column, a flag that shows that this vehicle is an underperformer (Loser).  Of course, there may be vehicles with both of those letters in the NOTES column.  To take care of the NOTES, though, you have full use of the array and its elements.  So, just test the appropriate elements and print either or both of those characters for the vehicles that fall into those categories.

Now, just a couple more things to do.  Bob wants two totals for the end of the report:  the total number of days that all vehicles have been rented; and the total revenue for all rental operations.  Both of these totals, of course, must also be accumulated within your while loop.  (Don't forget to display them at the end of the report.)  At the bottom of the loop, you need to "read" another set of data into the $vehicle array.


Related Discussions:- Php program

We are looking for expert coldfusion programmer, We are looking for Expert ...

We are looking for Expert ColdFusion Programmer - must be in Northern VA/DC area We are in want of an expert ColdFusion developer who can help us with a project that involves ec

Desire for help in metasearch infrastructure on website, Desire for help in...

Desire for help in Metasearch infrastructure on website We are seeing for experienced computer programmers that have built search engines met search or indexing sites in the pas

Want expert help in wordpress plugin development, Want expert help in Wordp...

Want expert help in Wordpress Plugin Development for Easy Digital Downloads We are utilizing a plugin called Easy Digital Downloads to allow clients to choose from selected file

Website graphic design and cakephp features, Website Graphic Design and Cak...

Website Graphic Design and CakePhP Features Project Description: Installation of a number of small features and changes on Cake PhP site, as well as changing the graphics of

We need help to modify a web page, We need help to Modify a web page We ...

We need help to Modify a web page We need help to Modify a web page to include posting a new category to our menu including add Add heading as well as text to our current web

Need to setup free pbx asterisk on digital ocean, Need to Setup Free PBX As...

Need to Setup Free PBX Asterisk on Digital Ocean Project Description: Setup Free PBX on Digital Ocean Droplet using Centos 6.5. Skills required are Asterisk PBX, SQL, Linu

Codes for fashion website built on magento, Fashion Website fixes Codes ...

Fashion Website fixes Codes for fashion website built on magento needs to be cleaned up. Job description: Current issues include: a) Coding on magento is making site un

Colspan and rowspan, Now let us see how to deal with ROWSPAN (Row Span) and...

Now let us see how to deal with ROWSPAN (Row Span) and COLSPAN (Column Span). If we desire the cell containing Ajay in Figure to be extended to the next cell as well and make th

How to get started with this, I want to start learning PHP programming, wha...

I want to start learning PHP programming, what I should do?

Session management, I need help with adding session management to my login ...

I need help with adding session management to my login webpage. It is the MVC method and has 2 models and 1 view alongside the login page of course. I just need assistance with the

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd