In theory I think that should work.  I haven't tested it to see.

--- In [email protected], "gentlemike2" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], Elke Hinze <julep8211@> wrote:
> > Why do you have your questions all in their own tables?  If you want
> to categorize the questions, then you should have a table for
> categories, a table to hold all your questions, and a table that
> relates the two.
> > 
> 
> I have another table not mentioned in the code snippet I gave that
> refers to a table that more-or-less relates the question table to the
> poll, and then separate tables for responses.  It was a decision I
> made after thinking long and hard about how to do this in the most
> efficient way.  I am going to have to do a little more studying.
> 
> > So you should have something like:
> > 
> > Cat_Table:  cat_id, cat_desc
> > Questions_Table: quest_id, quest_desc
> > Cat_Questions_Table:  cat_id, quest_id
> > 
> > The cat_questions table would hold the id for the particular
> question (quest_id) and it's related category (cat_id).
> > 
> > Then when you query, instead of looping through your array of
> tables, you just query the table and do a join.
> > 
> > $query = "SELECT a.cat_id as acat_id, b.quest_id as bquest_id,
> b.quest_desc, c.cat_id as ccat_id, c.quest_id as cquest_id
> >                 FROM cat_table a, questions_table b, cat_questions c
> >                   WHERE uid = $pid
> >                  AND a.cat_id = c.cat_id
> >                  AND b.quest_id = c.quest_id";
> 
> Thanks!  This is really helpful.  Up until now, I hadn't done anything
> with table joins.  I went back and read the part in my book about
> table joins.
> 
> One thing I am not clear on is this:  When I write the php code, and I
> put a joined table into an array would I refer to it as
> $myvar[questions.q_cat] (that is [table.field])?
> 
> Here is what I am thinking of doing -
> 
> $var1 = mysql_query("SELECT * from poll, questions where pid =
> ('".$pid."')");
> $var2 = mysql_fetch_array($var1);
> 
> Then I would refer to $var2[questions.q_cat].
> 
> Would that work?
> 
> By the way, thanks again.  This has been very helpful.
>


Reply via email to