Have you tried echoing out your query string to see what it is really trying to 
run?

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.

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";

You need to make sure to relate the ids to each other, or you won't return 
unique records.

What I described to you is normalization of tables.  I have included a few 
links describing why it's important and a good practice.

http://www.utexas.edu/its/windows/database/datamodeling/rm/rm7.html
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
http://www.webopedia.com/TERM/N/normalization.html

----- Original Message ----
From: gentlemike2 <[EMAIL PROTECTED]>
To: [email protected]
Sent: Friday, March 30, 2007 10:44:42 AM
Subject: [php-list] A Greeting and A Question









  


    
            I am glad I found you all.  I have been teaching myself php and 
mysql

out of books for several months now.  I haven't found anyone in my

community to chat with about these subjects.  It is nice to have

someone to bounce ideas off of, help, and get help from.



Here's my problem.  I am constructing polls from my database.  I have

it set up with a form to input poll questions, the type of question

(radio button, check box, select box).  I have each questions stored

in a separate table with a code for the type of question, and the

possible responses.  What I am trying to do in my code is render the

form with loops.



/* put the table names into an array */

$tableid= array('pollq1' , 'pollq2', 'pollq3', 'pollq3', 'pollq4',

'pollq5', 'pollq6', 'pollq7', 'pollq8', 'pollq9');

for ($i=0; $i <= $numberofqusetions] ; $i++) {

        $query = '"SELECT * from '. $tableid[$i] . ' where uid = '. $pid;. '"';

        $getresps = mysql_query( $query) or die (mysql_error( ));

        $resps = mysql_fetch_ array($getresps) ;

        /* The following line puts the answers into a two dimensional array

to make them easier to process when printing them.

        $a[$i] = array($resps[ "a1"], $resps["a2"] , $resps["a3"] ,

$resps["a4"] , $resps["a5"] , $resps["a6"] , $resps["a7"] , $resps["at8" ],

$resps["a9"] , $resps["a10" ]);

}



My problem is that no matter what I try I get a unknown column 'uid'

in 'where clause' error.  I have tried to structure the query in

different ways using different configurations of ' and " marks to get

this to work.  The I know it is seeing the value of the variable,

because when I structure the query like this:



$getresps = mysql_query( "SELECT * from ('".$tableid[ $i]."') where uid

= ('".$pid."') ") or die (mysql_error( ));



I get a syntax error near ''pollq1') where uid = ('1')' at line 1



I have used this syntax before with a standard variable (not array),

or I have used -- (".$table.") -- before and had it work.



What am I missing?  What am I doing wrong?





    
  

    
    




<!--

#ygrp-mlmsg {font-size:13px;font-family:arial, helvetica, clean, sans-serif;}
#ygrp-mlmsg table {font-size:inherit;font:100%;}
#ygrp-mlmsg select, input, textarea {font:99% arial, helvetica, clean, 
sans-serif;}
#ygrp-mlmsg pre, code {font:115% monospace;}
#ygrp-mlmsg * {line-height:1.22em;}
#ygrp-text{
font-family:Georgia;
}
#ygrp-text p{
margin:0 0 1em 0;}
#ygrp-tpmsgs{
font-family:Arial;
clear:both;}
#ygrp-vitnav{
padding-top:10px;font-family:Verdana;font-size:77%;margin:0;}
#ygrp-vitnav a{
padding:0 1px;}
#ygrp-actbar{
clear:both;margin:25px 0;white-space:nowrap;color:#666;text-align:right;}
#ygrp-actbar .left{
float:left;white-space:nowrap;}
.bld{font-weight:bold;}
#ygrp-grft{
font-family:Verdana;font-size:77%;padding:15px 0;}
#ygrp-ft{
font-family:verdana;font-size:77%;border-top:1px solid #666;
padding:5px 0;
}
#ygrp-mlmsg #logo{
padding-bottom:10px;}

#ygrp-vital{
background-color:#e0ecee;margin-bottom:20px;padding:2px 0 8px 8px;}
#ygrp-vital #vithd{
font-size:77%;font-family:Verdana;font-weight:bold;color:#333;text-transform:uppercase;}
#ygrp-vital ul{
padding:0;margin:2px 0;}
#ygrp-vital ul li{
list-style-type:none;clear:both;border:1px solid #e0ecee;
}
#ygrp-vital ul li .ct{
font-weight:bold;color:#ff7900;float:right;width:2em;text-align:right;padding-right:.5em;}
#ygrp-vital ul li .cat{
font-weight:bold;}
#ygrp-vital a {
text-decoration:none;}

#ygrp-vital a:hover{
text-decoration:underline;}

#ygrp-sponsor #hd{
color:#999;font-size:77%;}
#ygrp-sponsor #ov{
padding:6px 13px;background-color:#e0ecee;margin-bottom:20px;}
#ygrp-sponsor #ov ul{
padding:0 0 0 8px;margin:0;}
#ygrp-sponsor #ov li{
list-style-type:square;padding:6px 0;font-size:77%;}
#ygrp-sponsor #ov li a{
text-decoration:none;font-size:130%;}
#ygrp-sponsor #nc {
background-color:#eee;margin-bottom:20px;padding:0 8px;}
#ygrp-sponsor .ad{
padding:8px 0;}
#ygrp-sponsor .ad #hd1{
font-family:Arial;font-weight:bold;color:#628c2a;font-size:100%;line-height:122%;}
#ygrp-sponsor .ad a{
text-decoration:none;}
#ygrp-sponsor .ad a:hover{
text-decoration:underline;}
#ygrp-sponsor .ad p{
margin:0;}
o {font-size:0;}
.MsoNormal {
margin:0 0 0 0;}
#ygrp-text tt{
font-size:120%;}
blockquote{margin:0 0 0 4px;}
.replbq {margin:4;}
-->







[Non-text portions of this message have been removed]

Reply via email to