Welcome! Log In Create A New Profile

Advanced

Step 7 - Model and Colour Lists Duplicating Entries?

Posted by 37081888 
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
avatar Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 07:29PM
Hey guys....

I got the model and colour drop down lists to display the data from the tables in the DB however, when either list is clicked, a long list of duplicate entries show up and I don't know why. Could it be caused by the loops Mac gave us or this code from the tutorial letter I completed (most of it was already in the tut letter for step 7):

public function Fetch($model, $colour){

$query=mysql_query("SELECT * FROM model, colour"winking smiley;
$result = array();
while ($record = mysql_fetch_array($query)) {
$result[] = $record;//could something be wrong with this line?
}
return $result;
}

Thanks for the help.
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 07:48PM
Language: PHP
$query=mysql_query("SELECT * FROM model, colour") // model, colour are php variables - $model, $colour
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 07:53PM
Did you mean I should do something like this:

$query=mysql_query("SELECT * FROM model".$model.", colour".$colour.""winking smiley;

That didn't work when I tried it...unless I'm not understanding what you mean?

bigron11 Wrote:
-------------------------------------------------------
>
Language: PHP
> $query=mysql_query("SELECT * FROM model, colour") > // model, colour are php variables - $model, > $colour >
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 08:23PM
What is the purpose of passing two parameters to your function and then not using them ?

Language: PHP
$query=mysql_query("SELECT * FROM ';$model';, ';$colour'; " );

Is how your above query should be stated, but it will not work. You cannot extract data from 2 tables like that.
You need to clarify which attributes you are trying to extract from which table/s.
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 09:22PM
I tried what you recommended. It failed to pull the data and instead threw out this error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean

I've been getting that error with a number of other parameters I've tried...

What do you reckon?
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 09:24PM
Are two parameters supposed to be passed in the first place?? I ask that because the incomplete code that Mac gave us looks like this Fetch(.... , ....) which gives me the impression that two parameters need to be passed to the query...
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 09:43PM
What tables are you trying to extract data from ?

Where do $model and $colour get their values from ? They should be the name/s of the table/s you are trying to extract data from.
If there are multiple tables you need to use an INNER JOIN or possibly a WHERE clause.
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 10:38PM
From model and colour respectively. $model and $colour are the names of those two tables I'm trying to extract from. I'll try the INNER JOIN syntax you recommended and get back to you. Do you think the loops that follow the SQL query code Mac gave us may be causing the duplication or not? Did you notice any problems with your Availability table when you created it exactly as Mac described? I'm thinking it may be the cause of the duplication and the fact that no matter what model/colour combination I choose from the drop downs, the output after submitting the form is always "the model is not available in the colour"
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 23, 2013 10:50PM
The problem is the SQL query. You cannot extract data from multiple tables like that.
You need to structure the query correctly with INNER JOIN or a WHERE clause..
avatar
Mac
Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 08:12AM
The Fetch function is used to construct the color and model drop-down lists.

Language: PHP
public function Fetch(……, ……){ $query=mysql_query("SELECT * FROM ".$set_table_name." ORDER BY ".$order); .......

It is used twice - and you pass it the table name and the order... in order to get the color, and to get the model for the respective drop-down lists.
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 09:46AM
Where do I declare $set_table_name? When you say it's used twice, do you mean that there should be two separate queries: 1 for each table (model and colour)?

mac Wrote:
-------------------------------------------------------
> The Fetch function is used to construct the color
> and model drop-down lists.
>
>
Language: PHP
> public function Fetch(……, ……){ > $query=mysql_query("SELECT * FROM > ".$set_table_name." ORDER BY ".$order); > ....... >
>
> It is used twice - and you pass it the table name
> and the order... in order to get the color, and to
> get the model for the respective drop-down lists.
avatar
Mac
Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 10:33AM
The 1st argument is the table name, the 2nd the order. In defining the function you do not pass any arguments - you merely define the variables that will be passed as arguments.

If you look in the form section, you will see the Fetch function is used twice. So you need to figure out what arguments to pass... a tip is provided in the 1st use of the function.

I just noticed <FORM... is used twice in the code provided ... that is an error. Mmm, wonder who else picked it up. Consider it a red herring smiling smiley
Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 10:50AM
Hahaha... I did not pick it up.... eye popping smiley
Just checked my page and see I have the two
thank you Mac...

will be resubmiting tonight spinning smiley sticking its tongue out
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 08:12PM
Sorry for the late reply. I resolved the form error you pointed out. Now it doesn't duplicate anymore however, only model's list displays while colour is empty...what am I missing here??

mac Wrote:
-------------------------------------------------------
> The 1st argument is the table name, the 2nd the
> order. In defining the function you do not pass
> any arguments - you merely define the variables
> that will be passed as arguments.
>
> If you look in the form section, you will see the
> Fetch function is used twice. So you need to
> figure out what arguments to pass... a tip is
> provided in the 1st use of the function.
>
> I just noticed <FORM... is used twice in the code
> provided ... that is an error. Mmm, wonder who
> else picked it up. Consider it a red herring smiling smiley
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 08:26PM
Mac, what does $set_table_name do in your code? Can I rather use $model and $colour or does that variable contain both tables? Apologies if it's a silly question...
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 09:36PM
$set_table_name doesn't "do" anything, it is a variable name, which is passed to the function as a parameter.

The function Fetch() has 2 parameters - a table name ($set_table_name) and a column name ($order);

public function Fetch($set_table_name, $order)



You call the Function Fetch() twice , with different arguments -

Fetch("model table name", "column to order models by" );

Fetch("colour table name", "column to order colours by" );
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 24, 2013 09:40PM
Ahh, I see - thanks bigron! Gonna rearrange code now - will get back to you if I run into another snag or to let you know if it all works fine smiling smiley

bigron11 Wrote:
-------------------------------------------------------
> $set_table_name doesn't "do" anything, it is a
> variable name, which is passed to the function as
> a parameter.
>
> The function Fetch() has 2 parameters - a table
> name ($set_table_name) and a column name
> ($order);
>
> public function Fetch($set_table_name, $order)
>
>
>
> You call the Function Fetch() twice , with
> different arguments -
>
> Fetch("model table name", "column to order models
> by" );
>
> Fetch("colour table name", "column to order
> colours by" );
avatar Re: Step 7 - Model and Colour Lists Duplicating Entries?
October 25, 2013 09:29AM
YES! Problem solved thanks to your advice and code examples bigron! Both lists display and there are no duplicate records now thumbs up I made the mistake of changing the initial Fetch(... , ...) statement Mac gave because I didn't understand it's purpose...the problem then lied with the query statement itself. After reverting and touching up, it worked.
Sorry, only registered users may post in this forum.

Click here to login