Jump to content

Having trouble with php script


techboy992

Recommended Posts

Hi there

 

I have a bounch of if and elseif

But I can not get my wished result

<?php
require_once("dbase.php");
$gameid=$_GET["gameid"];
$cardid=$_GET["cardid"];

$result=mysqli_query($conn, "SELECT * from games where gameid='".$gameid."'");
while($row=mysqli_fetch_array($result)){
$n1=$row["n1"];
$n2=$row["n2"];
$n3=$row["n3"];
$n4=$row["n4"];
$n5=$row["n5"];
$n6=$row["n6"];
$n7=$row["n7"];
$n8=$row["n8"];
$n9=$row["n9"];
$n10=$row["n10"];
$n11=$row["n11"];
$n12=$row["n12"];
$n13=$row["n13"];
$n14=$row["n14"];
$n15=$row["n15"];
$n16=$row["n16"];
$n17=$row["n17"];
$n18=$row["n18"];
$n19=$row["n19"];
$n20=$row["n20"];
$n21=$row["n21"];
$n22=$row["n22"];
$n23=$row["n23"];
$n24=$row["n24"];
$n25=$row["n25"];
$n26=$row["n26"];
$n27=$row["n27"];
$n28=$row["n28"];
$n29=$row["n29"];
$n30=$row["n30"];
$n31=$row["n31"];
$n32=$row["n32"];
$n33=$row["n33"];
$n34=$row["n34"];
$n35=$row["n35"];
$n36=$row["n36"];
$n37=$row["n37"];
$n38=$row["n38"];
$n39=$row["n39"];
$n40=$row["n40"];
$n41=$row["n41"];
$n42=$row["n42"];
$n43=$row["n43"];
$n44=$row["n44"];
$n45=$row["n45"];
$n46=$row["n46"];
$n47=$row["n47"];
$n48=$row["n48"];
$n49=$row["n49"];
$n50=$row["n50"];
$n51=$row["n51"];
$n52=$row["n52"];
$n53=$row["n53"];
$n54=$row["n54"];
$n55=$row["n55"];
$n56=$row["n56"];
$n57=$row["n57"];
$n58=$row["n58"];
$n59=$row["n59"];
$n60=$row["n60"];
$n61=$row["n61"];
$n62=$row["n62"];
$n63=$row["n63"];
$n64=$row["n64"];
$n65=$row["n65"];
$n66=$row["n66"];
$n67=$row["n67"];
$n68=$row["n68"];
$n69=$row["n69"];
$n70=$row["n70"];
$n71=$row["n71"];
$n72=$row["n72"];
$n73=$row["n73"];
$n74=$row["n74"];
$n75=$row["n75"];
}
//echo $n75;
$result=mysqli_query($conn, "SELECT * from cards where cardid='".$cardid."'");
while($row=mysqli_fetch_array($result)){
$cardis=$row["cardid"];
$nu1=$row["n1"];
$nu2=$row["n2"];
$nu3=$row["n3"];
$nu4=$row["n4"];
$nu5=$row["n5"];
$nu6=$row["n6"];
$nu7=$row["n7"];
$nu8=$row["n8"];
$nu9=$row["n9"];
$nu10=$row["n10"];
$nu11=$row["n11"];
$nu12=$row["n12"];
$nu13=$row["n13"];
$nu14=$row["n14"];
$nu15=$row["n15"];
$nu16=$row["n16"];
$nu17=$row["n17"];
$nu18=$row["n18"];
$nu19=$row["n19"];
$nu20=$row["n20"];
$nu21=$row["n21"];
$nu22=$row["n22"];
$nu23=$row["n23"];
$nu24=$row["n24"];
$nu25=$row["n25"];
}

//count called numbers
$result=mysqli_query($conn, "SELECT COUNT(*) AS total FROM numbers$gameid");
while($row=mysqli_fetch_array($result))
$totalcards=$row["total"];

//if($total < 30){
$result=mysqli_query($conn, "SELECT COUNT(*) AS total FROM cards where gameid='".$gameid."' AND userid='".$user_id."'");
while($row=mysqli_fetch_array($result))
$totalcards=$row["total"];

//Airplane

if($n2==$nu2 AND $n3==$nu3 AND $n4==$nu4 AND $n8==$nu8 AND $n16==$nu16 AND $n18==$nu18 AND $n19==$nu19 AND $n20==$nu20 AND $n23==$nu23){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//anchor

elseif($n1==$nu1 AND $n4==$nu4 AND $n6==$nu6 AND $n10==$nu10 AND $n11==$nu11 And $n12==$nu12 AND $n14==$nu14 AND $n15==$n15 AND $n16==$nu16 AND $n20==$nu20 AND $n21==$nu21 AND $n24==$nu24){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//bowtie

elseif($n4==$nu4 AND $n5==$nu5 AND $n9==$nu9 AND $n10==$nu10 AND $n16==$nu16 AND $n17==$nu17 AND $n21==$nu21 AND $n22==$nu22){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//cents

elseif($n7==$nu7 AND $n8==$nu8 AND $n9==$nu9 and $n11==$nu11 and $n14==$nu14 and $n15==$nu15 and $n17==$nu17 and $n19==$nu19){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//champagnebottle

elseif($n8==$nu8 AND $n9==$nu9 and $n10==$nu10 and $n11==$nu11 and $n12==$nu12 and $n14==$nu14 and $n15==$nu15 and $n18==$nu18 and $n19==$nu19 and $n20==$nu20){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//champagneglassemty

elseif($n1==$n1 and $n7==$nu7 and $n10==$nu10 and $n14==$nu14 and $n15==$nu15 and $n17==$nu17 and $n20==$nu20 and $n21==$nu21){
	$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//champagneglassfull

elseif($n1==$nu21 and $n6==$nu6 and $n7==$nu7 and $n10==$nu10 and $n11==$nu11 and $n12==$nu12 and $n14==$nu14 and $n15==$nu15 and $n16==$nu16 and $n17==$nu17 and $n20==$nnu20 and $n21==$nu21){
	$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//check mark

elseif($n3==$nu3 and $n4==$nu4 and $n5==$nu5 and $n9==$nu9 and $n17==$nu17 and $n21==$nu21){
	$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//chessboard

elseif($n1==$nu1 and $n3==$nu3 and $n5==$nu5 and $n7==$nu7 and $n9==$nu9 and $n11==$nu11 and $n15==$nu15 and $n17==$nu17 and $n19==$nu19 and $n21==$nu21 and $n23==$nu23 and $n25==$nu25){
	$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//cornered

elseif($n2==$nu2 and $n3==$nu3 and $n4==$nu4 and $n5==$nu5 and $n8==$nu8 and $n9==$nu9 and $n10==$nu10 and $n14==$nu14 and $n15==$nu15 and $n20==$nu20){
	$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//diamond

elseif($n3==$nu3 and $n7==$nu7 and $n8==$nu8 and $n9==$nu9 and $n11==$nu11 and $n12==$nu12 and $n14==$nu14 and $n15==$nu15 and $n17==$nu17 and $n18==$nu18 and $n19==$nu19 and $n23==$nu23){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//dollarsign

elseif($n1==$nu1 and $n2==$nu2 and $n3==$nu3 and $n5==$nu5 and $n6==$nu6 and $n8==$nu8 and $n10==$nu10 and $n11==$nu11 and $n12==$nu12 and $n14==$nu14 and $n15==$nu15 and $n16==$nu16 and $n18==$nu18 and $n20==$nu20 and $n21==$nu21 and $n23==$nu23 and $n24==$nu24 and $n25==$nu25){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//doublebingo

elseif($n3==$nu3 and $n6==$nu6 and $n7==$nu7 and $n8==$nu8 and $n9==$nu9 and $n10==$nu10 and $n18==$nu18 and $n23==$nu23){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";		
}
//eightpack

elseif($n1==$nu1 and $n2==$nu2 and $n3==$nu3 and $n4==$nu4 and $n6==$nu6 and $n7==$nu7 and $n8==$nu8 and $n9==$nu9){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//explosion

elseif($n1==$nu1 and $n5==$nu5 and $n8==$nu8 and $n12==$nu12 and $n14==$nu14 and $n18==$nu18 and $n21==$nu21 and $n21==$nu21 and $n25==$nu25){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//fourcorners

elseif($n1==$nu1 and $n5==$nu5 and $n21==$nu21 and $n25==$nu25){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//gobingo

elseif($n16==$nu16 and $n17==$nu17 and $n18==$nu18 and $n19==$nu19 and $n20==$nu20 and $n21==$nu21 and $n22==$nu22 and $n23==$nu23 and $n24==$nu24 and $n25==$nu25){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//hangman

elseif($n1==$nu1 and $n2==$nu2 and $n3==$nu3 and $n5==$nu5 and $n6==$nu6 and $n11==$nu11 and $n15==$nu15 and $n16==$nu16 and $n17==$nu17 and $n18==$nu18 and $n19==$nu19 and $n23==$nu23 and $n25==$nu25){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
//happyface

elseif($n4==$nu4 and $n6==$nu6 and $n10==$nu10 and $n15==$nu15 and $n16==$nu16 and $n20==$nu20 and $n24==$nu24){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}
//jet

elseif($n3==$nu3 and $n7==$nu7 and $n10==$nu10 and $n11==$nu11 and $n12==$nu12 and $n13==$nu13 and $n14==$nu14 and $n15==$nu15 and $n17==$nu17 and $n20==$nu20 and $n23==$nu23){
$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";	
}




//fullcard

elseif($n1==$nu1 and $n2==$nu2 and $n3==$nu3 and $n4==$nu4 and $n5==$nu5 and $n6==$nu6 and $n7==$nu7 and $n8==$nu8 and $n9==$nu9 and $n10==$nu10 and $n11==$nu11 and $n12==$nu12 and $n13==$nu13 and $n14==$nu14 and $n15==$nu15 and $n16==$nu16 and $n17==$nu17 and $n18==$nu18 and $n19==$nu19 and $n20==$nu20 and $n21==$nu21 and $n22==$nu22 and $n23==$nu23 and $n24==$nu24 and $n25==$nu25){
	$link="<a href='progresive.php?cardid=$cardid&gameid=$gameid'><font color='fffff'><b>BINGO</b></font>";
}
echo $link;
if(!$link){
echo "	
<meta http-equiv='Refresh' content='0; URL=progressive.php?cardid=$cardid&gameid=$gameid' />	
";
}

else {
	echo "$link
	<meta http-equiv='Refresh' content='3; URL=progressive.php?cardid=$cardid&gameid=$gameid' />
	";
}

what I want to archive is if the numbers is fitting together then the link with bingo is showing in the end of the script.

 

Link to comment
Share on other sites

Task 1 - sort out the errors in your if() statements. I found 3 so far

  • $n1==$nu21
  • $n20==$nnu20
  • $n21==$nu21 and $n21==$nu21

Don't create separate tables for each game (eg ...FROM numbers$gameid )

 

Why are you selecting 75 numbers when you only use 25?

 

Normalize your data, db tables are not spreadsheets.

 

 

Link to comment
Share on other sites

You appear to be checking that the nth ball called is in the nth square on the user's card which will raise the odds of a win considerably.

 

You should be checking if the number in each each square has been called at all, then check if the called squares match one of your patterns.

 

For the benefit of those who don't know what you are doing, I have listed you various patterns (based on the numbers you are testing in the if() statements) in the image below. It makes your comments make more sense :)

 

The cells apparently number top to bottom with 1 - 5 in the first column. From a programming perspective it would be better to put 0 - 4 in the first row, 5 - 9 in second row etc.

 

FYI, this is the code to produce that list of patterns. Note the use of the array, which is the direction you should be taking, instead of all those if() statements.

<?php
$wins = [
        'airplane' =>   [2,3,4,8,16,18,19,20,23],
        'anchor'   =>   [1,4,6,10,11,12,14,15,16,20,21,24],
        'bowtie'   =>   [4,5,9,10,16,17,21,22],
        'cents'    =>   [7,8,9,11,14,15,17,19],
        'bottle'   =>   [8,9,10,11,12,14,15,18,19,20],
        'glassempt'=>   [1,7,10,14,15,17,20,21],
        'glassfull'=>   [1,6,7,10,11,12,14,15,16,17,20,21],
        'checkmark'=>   [3,4,5,9,17,21],
        'chess'    =>   [1,3,5,7,9,11,15,17,19,21,23,25],
        'cornered' =>   [2,3,4,5,8,9,10,14,15,20],
        'diamond'  =>   [3,7,8,9,11,12,14,15,17,18,19,23],
        'dollar'   =>   [1,2,3,5,6,8,10,11,12,14,15,16,18,20,21,23,24,25],
        'double'   =>   [3,6,7,8,9,10,18,23],
        'eightpack'=>   [1,2,3,4,6,7,8,9],
        'explosion'=>   [1,5,8,12,14,18,21,25],
        'corners4' =>   [1,5,21,25],
        'gobingo'  =>   [16,17,18,19,20,21,22,23,24,25],
        'hangman'  =>   [1,2,3,5,6,11,15,16,17,18,19,23,25],
        'happyface'=>   [4,6,10,15,16,20,24],
        'jet'      =>   [3,7,10,11,12,13,14,15,17,20,23],
        'fullcard' =>   range(1,25)
        ];

$out = '';
        
foreach ($wins as $k => $nums) {
    $pattern = array_fill(0,25,' ');
    foreach ($nums as $n) {
        $pattern[$n-1] = '•';
    }

    $out .= "<div class='pattern'>\n$k<br>\n<pre>\n";
    for ($i=0; $i<5; $i++) {
        $out .= "<span class='faint'>|</span>";
        for($j=0; $j<21; $j+=5) {
            $out .= "{$pattern[$i+$j]}<span class='faint'>|</span>";
        }
        $out .= "\n";
    }
    $out .= "</pre></div>\n";
}

?>
<html>
<head>
<title>Patterns</title>
<style type='text/css'>
div.pattern {
    background-color: black;
    color: white;
    text-align: center;
    width: 12%;
    height: 120px;
    margin-left: 5px;
    margin-bottom: 5px;
    float: left;
}
.faint {
    color: #777;
}
</style>
</head>
<body>
<?=$out?>
</body>
</html>

post-3105-0-93223400-1445256230_thumb.png

Link to comment
Share on other sites

I have also been working a little to try figure out how to do this

 

I found array_intersect(array1,array2);

 

The run:

$result=array_intersect($numbers,$fullcard); print_r($result);

result was Array ( [5] => 6 [6] => 7 [29] => 30 [44] => 45 [47] => 48 [72] => 75 ). which is actilly the numbers in first row on the plate and the numbers that was drawn,

 

but now I am stuck again to actilly check and be able to show a bingo button in buttom of the card

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.