As part of my "big" project I need to append the info in a couple of MySQL database tables into a single table. I'd prefer to do this in php rather than create a new table, even temporary, in MySQL. It also seems like it should be an easy task but I can't quite figure it out.
Here're the particulars...
Both tables, "responses"and "comments" have the general structure of
"userid", "questionid", "choiceid", and "response".
The first three fields are identical in structure. The fourth one, though, is typed as charvar(30) in "responses" and contains "short" responses to questions. In the second table, "comments", field4 is typed as "text" for long, extended answers to questions.
The code I'm currently using is:
$query2="select * from responses
where userid='$keyid'";
$query3="select * from comments
where userid='$keyid'";
$result2 = mysql_query($query2, $db_conn);
$num_results2 = mysql_num_rows($result2);
$result3 = mysql_query($query3, $db_conn);
$num_results3 = mysql_num_rows($result3);
$j=0;
for ($j; $j<$num_results2; $j++) {
$row4=mysql_fetch_array($result2);
$registrant=$row4["userid"];
$question=$row4["questionid"];
$choice=$row4["choiceid"];
$response1=$row4["response"];
echo $n." ".$registrant." ".$question." ".$choice." ".$response1."<br>";
$n++;
}
$j=0;
for ($j; $j<$num_results3; $j++) {
$row5=mysql_fetch_array($result3);
$registrant=$row5["userid"];
$question=$row5["questionid"];
$choice=$row5["choiceid"];
$response1=$row5["response"];
echo $n." ".$registrant." ".$question." ".$choice." ".$response1."<br>";
$n++;
}
This results in the contents of the two tables being listed sequentially, with the contents of "responses" being first and "comments" second. What I'd like to do is have the responses in a single array sorted on $question and $choice so the results are listed sequentially, based on $question.
Suggestions will be greatly appreciated!
Thanks,
Jim


LinkBack URL
About LinkBacks



Reply With Quote
Bookmarks