以下是我尝试使用MySQL
运行的PHP
代码。我从RelationA变量和RelationB变量给它两个值。读取后,脚本会解析结果表并生成以下输出。
<?PHP
$Relation_a1=$_POST["relationa1"];
$Relation_a2=$_POST["relationa2"];
$Relation_a3=$_POST["relationa3"];
$Relation_a4=$_POST["relationa4"];
$Relation_a5=$_POST["relationa5"];
$Relation_a6=$_POST["relationa6"];
$Relation_a7=$_POST["relationa7"];
$Relation_a8=$_POST["relationa8"];
$Relation_a9=$_POST["relationa9"];
$Relation_a10=$_POST["relationa10"];
$Relation_b1=$_POST["relationb1"];
$Relation_b2=$_POST["relationb2"];
$Relation_b3=$_POST["relationb3"];
$Relation_b4=$_POST["relationb4"];
$Relation_b5=$_POST["relationb5"];
$Relation_b6=$_POST["relationb6"];
$Relation_b7=$_POST["relationb7"];
$Relation_b8=$_POST["relationb8"];
$Relation_b9=$_POST["relationb9"];
$Relation_b10=$_POST["relationb10"];
$connect=mysql_connect('localhost','user','user')
or die('could not open:'. mysql_error());
mysql_select_db('user_db');
$result1=mysql_query("SELECT GROUP_CONCAT(id SEPARATOR '_') into @var1 FROM relative1 WHERE name='$Relation_a1' OR name='$Relation_a2' OR name='$Relation_a3' OR name='$Relation_a4' OR name='$Relation_a5' OR name='$Relation_a6' OR name='$Relation_a7' OR name='$Relation_a8' OR name='$Relation_a9' OR name='$Relation_a10'");
$result2=mysql_query("SELECT GROUP_CONCAT(id SEPARATOR '_') into @var2 FROM relative2 WHERE name='$Relation_b1' OR name='$Relation_b2' OR name='$Relation_b3' OR name='$Relation_b4' OR name='$Relation_b5' OR name='$Relation_b6' OR name='$Relation_b7' OR name='$Relation_b8' OR name='$Relation_b9' OR name='$Relation_b10'");
$result=mysql_query("SELECT final_result FROM result WHERE id IN (SELECT GROUP_CONCAT(@var1,'-',@var2))");
$ncols=mysql_num_fields($result);/* How many columns (fields) */
$queryResults = NULL;
if( mysql_num_rows($result)>0)
{
print "<br>";
print "<table cellpadding=0 cellspacing=0 width=100% border=1 bordercolor=skyblue>";
print "<tr>";
for ( $i=0; $i<$ncols; $i++ )
{
$column_name=mysql_field_name($result,$i); /* field name */
print "<td align=center><b>".$column_name."</b></td>";
}
print "</tr>";
$total=0;
while ( $row = mysql_fetch_array($result) ) /* process result row-by-row */
{
print "<tr>";
$total++;
for ( $i=0; $i<$ncols; $i++ )
{
$column_value=$row[$i]; /* field value */
print "<td align=center>".$column_value . "</td>";
}
}
mysql_free_result($result);
}
else
{
echo ("<h3>There is no data pertaining to you request</h3>");
}
?>
无论我向Relation表提供什么输入,我的输出总是一样的。