|
 |
pro_php thread: Category System Question
Message #1 by "Bill" <bige88fan@c...> on Sat, 16 Nov 2002 20:39:35
|
|
Sorry to have wasted your time Jorge. But after thinking about it, I am
sticking with a double queried version. Basically I changed my table layout
to reduce queries in other areas of my script, and now I have better
organization, and I should also maintain the same continuity of performance
because by removing other unnecessary queries from other areas of the script
because of my new category table layout, it should all even out.
-Thanks
Kyle.
----- Original Message -----
From: "jorge" <jorge@d...>
To: "professional php" <pro_php@p...>
Sent: Saturday, November 16, 2002 8:02 PM
Subject: [pro_php] Re: Category System Question
> Hi Bill
> I am just trying to help this pretty well the same query just trying to
> point the use of the dots.
> $query = "SELECT id,parentid FROM categories WHERE id=parentid ORDER BY
> parent id"
> $query ="SELECT id AS sub, parentid AS parent FROM categories WHERE id
> parentid"
> $query ="SELECT id AS categories.sub, categories.parentid AS parent FROM
> categories GROUP BY categories.parentid"
>
>
> I read your query and i found what i think are some problems over there
that
> confuse me
> 1.-sub.parent_id=parent.id is your table name sub?? since you are calling
> parent_id FROM table sub = sub.parentid in the WHERE clause
> then you call id FROM table parent?
> cat_test sub (cat_test AS sub, ?) or cat_test_sub? there is a white space
> over there? which is the real table name?
>
> Saludos Jorge
> :)
>
> ----- Original Message -----
> From: "Bill" <bige88fan@c...>
> To: "professional php" <pro_php@p...>
> Sent: Saturday, November 16, 2002 8:39 PM
> Subject: [pro_php] Category System Question
>
>
> > Back in October I made a post about how to display sub-categories under
> > categories. I read Nik's advice on using a single queried version, to do
> > that, I made some table modifications, and now I'm stuck. Here is my
> > table structure.
> >
> > Table Name: categories
> > Layout:
> > id parentid name descr
> > 1 0 Downloads Downloads area
> > 2 1 Drivers Drivers Dl's
> > 3 0 Other Stuff Other Downloads
> > 4 3 Books Great Books
> >
> > Ok, well that is a ficticious table, but it has what I need to do with
> > it. I think you can see by looking at the table on what I need to do.
All
> > of the parent categories are labeled with a parent_id of '0', the sub
> > category has the parent_id field equal to the id of it's parent. For
> > example, Books is a sub-category of Other Stuff because it's parent_id
is
> > 3, and the id of the parent category "Other Stuff", is 3. So let's cut
to
> > the chase, I need to know how I can diplay each parent category with
it's
> > *belonged to* sub-categories underneath it. Basically I've tried code
> > such as:
> >
> > <?php
> > require "./functions.php";
> > connect();
> >
> > $query = "SELECT * FROM cat_test sub,cat_test parent WHERE
> > sub.parent_id=parent.id ORDER BY name ASC ";
> > $result = mysql_query($query);
> >
> > if($result && (mysql_num_rows($result) > 0) )
> > {
> > $def_headingid = 0;
> >
> > echo "<SELECT name=\"bob\">\n";
> > while($row = mysql_fetch_array($result))
> > {
> > // start a new main category?
> > if($row[parent_id] == $def_headingid)
> > {
> > echo " <OPTION value=\"\">"
> > . $row[name]
> > . "</OPTION>\n";
> > $last_parent = $row[id];
> > }
> > else
> > {
> > echo " <OPTION value=\"{$row[id]}\"> - "
> > . $row[name]
> > . "</OPTION>\n";
> > }
> > }
> > echo "</SELECT>\n";
> > }
> >
> > mysql_close();
> > ?>
> >
> > But that doesn't work. I mean it displays all the categories, but the
sub-
> > categories don't even belong to the parents in the code above. And also,
> > it doesn't matter what kind of a format it is in, doesn't have to be
form
> > based...can anybody help me out?
> >
> > Thanks,
> > -Kyle.
>
>
>
>
|
|
 |