Welcome! Log In Create A New Profile

Advanced

Portfolio_select page

Posted by 50638459_Leolee 
Announcements Last Post
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
Portfolio_select page
July 30, 2013 12:31PM
Hi Mac and fellow students, Maybe its a bit too early for this question but I've been scrapping my head for 2 weeks now and I'm going crazy. In the select page of the portfolio, at the end where we echo out a table with the model, colour and availability displaying yes/no., I seem to have a huge a problem. My table displays only yes even if the model is not available in that colour. I have changed my code multiple times trying to sort it out, I've run out of options. It seems to only fetch one row of the colour_id in the availability table and displays yes to all the other models. Please help, I do not want to repeat this module for the 3rd time. Please I need someone's assistance and I hope you'll understand the question. Thank you.
avatar
Mac
Re: Portfolio_select page
July 30, 2013 05:33PM
It all depends on your approach, but generally the availability table has three columns:

Language: PHP
`avail_id` int(11) DEFAULT NULL, `model_id` int(11) NOT NULL, `colour_id` int(11) NOT NULL

If there is a row in this table, then clearly this model is available in this colour - you do not have yes or no in this table. So models (by their model_id) that are not in this table is not available in any colour.

No there are many options available here, and I cannot give the correct approach as I want to see how you approach it (I am lenient here).

I will provide code that someone submitted that thought was quite novel


Language: PHP
for($i=1; $i<20; $i++){ //Start for loop for 19 models that I know I have inmodel table for ($i2=1; $i2<7; $i2++){ //Start for loop inside MODEL for loop to for eac colour that there is.   //query model table to get the model name where model_id=$1   //query colour table to get the colour name where model_id=$i2   //query availability where the model_id=$1 and colour_id=$i2 //get the num of rows of the query, If there is a row, then set a var (say $is_avail) to yes, else no.   //echo the results e.g. model name, model color, $is_avail     } } echo "</table>";

There are much better ways of course, and using OOP is premium. For now, I want you to use whatever logic required to create the table
Re: Portfolio_select page
July 31, 2013 08:55AM
Thank you Mac, Let me work through it. Appreciate the help.
Sorry, only registered users may post in this forum.

Click here to login