Welcome! Log In Create A New Profile


Prac available

Posted by Mac 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Prac available
April 28, 2009 10:43AM
You can download the prac.
Re: Prac available
April 30, 2009 10:49AM
Hi Mac,

Going through the practical I am lloking at the table definitions. You are wanting them to be exactly the same as what you have on your server. Don't we need field lengths specified? I see you only gave us field names?
Re: Prac available
April 30, 2009 10:50AM
SORRY! I see the field lengths now!!! Blonde moment!
Re: Prac available
April 30, 2009 11:14AM
It must be the same since you will send your prac to me, which I will then test using my (same) database
Re: Prac available
May 05, 2009 11:25AM
I have a few questions:

When you test our project are you gonna use a database that is already populated with values. The reason I ask is the format that certain values have in the database could mean that the input that we test for and enter into the database via our site could result in problems. For example your format for sex is char(2). If on my site I enter values "ma" for male and "fe" for female, it would result it problems if your db has "m" for male and "f" for female.

In your db you provided you have dob as a varchar(8). Would it cause problems if i changed it to the "date" format.

In the document theres a table giving the fields of the db and explanations of them. In the table theres a field in the course_student table called fmark, but the MySQL dump at the end doesn't create that field. From the requirements it seems we dont need that field, so can I assume it isn't neccessary?
Re: Prac available
May 06, 2009 07:28AM
I will use your app to populate my database, so as long as the structure is the same it does not matter. sex has char(2), so if you provide a drop down with values ma and fe, or m and f, or whatever (as long as it is equal or less than 2) then it does not matter. the fmark is not used in the app, I just placed it there to give an indication of how you could develop your db. If you add it manually, not using the dump, then it won't be in the way, except that you will have to consider it if you do inserts into the db. Of course I will pick up if you decide to use it (maybe add a facility to enter marks - not required!) but I'll just look at your code then. You can't change dob to date format. Just use it as is, and code around that.
Re: Prac available
May 06, 2009 12:07PM
ok thanks Mac,

I'm having some issues using the date in that format though.

To make any use of the date in my application I need to split it into year, month and day, for it to make any sense. It wasn't a problem with the data in mysql date format, since I could split it using the "-" as a seperator like this:

list($year, $month, $day) = split("-", $dob);

The date format you have will be for example 19801231, which like that I have managed to split using:

list($year,$month_day) = str_split($dob, 4);
list($month, $day) = str_split($month_day, 2);

however not all the dates will be the same length for instance 1 January 1980 will be 198011, since in my form i am reading them in seperately from year, month and day dropdowns and then combining them into 1 string. This means that the leading 0 on a month like january is cut off. I also cant combine the new string using "-" as a seperator because theres only 8 characters in the date string type.

So in cases where the month or day is a single digit, the above code won't work.

Is there an easier way to do this that I'm missing. I really don't want to sacrifice my date selection dropdown menu's since I feel thats the best way to input dates without uneccessary verification code. Its also simpler for the user.


Managed to solve this problem.

I found a way to add the leading "0" when neccessary before combining the year,month and day to add to the db.

you can use the following function:

$month = sprintf("%02d", $month);
$day = sprintf("%02d", $day);

$dob = $year . $month . $day

This will ensure that the $dob is always 8 characters and splitting it up again using the code above isn't a problem.

source: http://www.codingforums.com/archive/index.php/t-104715.html

Hopefully others will find this usefull.
Re: Prac available
May 07, 2009 09:04AM
Precisely smiling smiley Google is your friend - something I always press for! A longer but less effcient way to do it (this is an introductory course and I do not expect everybody to understand your solution) is to simply run a few if's/elses - if($day==1){$day='01';}...... $day==9. While it is good programming practice to try and shorten your code, the step by step example I gave is simple and straight forward and logical (for the beginner). For example, you might write code, and looking at it afterwards see that by using functions, you code more efficient. Later you will start thinking if functions (and the functions in classes) before you start coding. But that comes through experience, so I am a great believer in the longer (and necessarily less efficient way) route when starting out. Having said all of that, if you find solutions such as you have, then use it by all means - as long as you understand how it works!

another way: $day= ++$day< 10 ? '0'.$day: $day;

Then again, if you call the day correctly with PHP's date function, i.e. call day by 'd', then it will already have the 0 in front....
Re: Prac available
May 14, 2009 09:47AM
Hi Mac, just a quick question.

Going through the prac, I noted that there is an fmark (final year mark) in the table for the DATABASE STRUCTURE (Fields in order as they appear in tables). The fmark field does not appear on the sql definitions though. Do we need to add this field or not?
Re: Prac available
May 14, 2009 10:31AM
This was answered here above... smiling smiley
Re: Prac available
May 14, 2009 12:14PM
Sorry! Such a small statememnt, I missed that one!
Sorry, only registered users may post in this forum.

Click here to login