我已经设法做了我想要的,但是如果用户与第一个号码不匹配,那么它表示他们没有匹配任何他们可以匹配5等...想想它像一个彩票:)
<?
include "includes/db_connect.php";
$email=$_SESSION["real_name"];
$sql="SELECT * from users WHERE email='$email'";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){ // Start looping table row
$one2=$rows['1'];
$two2=$rows['2'];
$three2=$rows['3'];
$four2=$rows['4'];
$five2=$rows['5'];
$six2=$rows['6'];
{
$q = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$one2' OR `2` = '$one2' OR `3` = '$one2' OR `4` = '$one2' OR `5` = '$one2' OR `6` = '$one2' LIMIT 1");
$get = mysql_num_rows($q);
if($get == 0) {
echo 'Sorry you didnt match anything';
} else {
$q1 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$two2' OR `2` = '$two2' OR `3` = '$two2' OR `4` = '$two2' OR `5` = '$two2' OR `6` = '$two2' LIMIT 1");
$get1 = mysql_num_rows($q1);
if($get1 == 0) {
echo 'You matched one number';
} else {
$q2 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$three2' OR `2` = '$three2' OR `3` = '$three2' OR `4` = '$three2' OR `5` = '$three2' OR `6` = '$three2' LIMIT 1");
$get2 = mysql_num_rows($q2);
if($get2 == 0) {
echo 'You matched two numbers';
} else {
$q3 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$four2' OR `2` = '$four2' OR `3` = '$four2' OR `4` = '$four2' OR `5` = '$four2' OR `6` = '$four2' LIMIT 1");
$get3 = mysql_num_rows($q3);
if($get3 == 0) {
echo 'You matched three numbers';
} else {
$q4 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$five2' OR `2` = '$five2' OR `3` = '$five2' OR `4` = '$five2' OR `5` = '$five2' OR `6` = '$five2' LIMIT 1");
$get4 = mysql_num_rows($q4);
if($get4 == 0) {
echo 'You matched four numbers';
} else {
$q5 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$six2' OR `2` = '$six2' OR `3` = '$six2' OR `4` = '$six2' OR `5` = '$six2' OR `6` = '$six2' LIMIT 1");
$get5 = mysql_num_rows($q5);
if($get5 == 0) {
echo 'You matched five numbers';
} else {
echo 'You matched all the numbers';
}
?>
<? }}}}}}} ?>
现在你已经看过代码了,我想我需要解释一下它的更多内容。 one2-six2是用户选择的6个数字。 它们需要与“数字”表中的数字相匹配 它可以工作,但如果用户不匹配他们的第一个数字(one2)但匹配(two2),那么它表示他们没有匹配任何。
有什么建议吗?
答案 0 :(得分:0)
<?
include "includes/db_connect.php";
$email=$_SESSION["real_name"];
$sql="SELECT * from users WHERE email='$email'";
$result=mysql_query($sql);
$number = 0;
$number_wrong = 0;
while($rows=mysql_fetch_array($result)){ // Start looping table row
$one2=$rows['1'];
$two2=$rows['2'];
$three2=$rows['3'];
$four2=$rows['4'];
$five2=$rows['5'];
$six2=$rows['6'];
{
$q = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$one2' OR `2` = '$one2' OR `3` = '$one2' OR `4` = '$one2' OR `5` = '$one2' OR `6` = '$one2' LIMIT 1");
$get = mysql_num_rows($q);
if($get == 0) {
$number++;
} else {
$number_wrong++;
}
$q1 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$two2' OR `2` = '$two2' OR `3` = '$two2' OR `4` = '$two2' OR `5` = '$two2' OR `6` = '$two2' LIMIT 1");
$get1 = mysql_num_rows($q1);
if($get1 == 0) {
$number++;
} else {
$number_wrong++;
}
$q2 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$three2' OR `2` = '$three2' OR `3` = '$three2' OR `4` = '$three2' OR `5` = '$three2' OR `6` = '$three2' LIMIT 1");
$get2 = mysql_num_rows($q2);
if($get2 == 0) {
$number++;
} else {
$number_wrong++;
}
$q3 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$four2' OR `2` = '$four2' OR `3` = '$four2' OR `4` = '$four2' OR `5` = '$four2' OR `6` = '$four2' LIMIT 1");
$get3 = mysql_num_rows($q3);
if($get3 == 0) {
$number++;
} else {
$number_wrong++;
}
$q4 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$five2' OR `2` = '$five2' OR `3` = '$five2' OR `4` = '$five2' OR `5` = '$five2' OR `6` = '$five2' LIMIT 1");
$get4 = mysql_num_rows($q4);
if($get4 == 0) {
$number++;
} else {
$number_wrong++;
}
$q5 = mysql_query("SELECT * FROM `numbers` WHERE `1` = '$six2' OR `2` = '$six2' OR `3` = '$six2' OR `4` = '$six2' OR `5` = '$six2' OR `6` = '$six2' LIMIT 1");
$get5 = mysql_num_rows($q5);
if($get5 == 0) {
$number++;
} else {
$number_wrong++;
}}
Echo 'you got '.$number.' Numbers right and '.$number_wrong.' Numbers wrong.';
?>
抱歉在我的手机上这样做了。不是最简单的。请检查语法。