Jump to content

Recommended Posts

Hi I have a lottery viewer which works. What I want to do is check if a number is a match and change the colour of the ball. Right now it just returns 0 or 1. I thought black 000000 normal and blue 0000ff.

Is there a way of deleting the code section. Spelling mistake $Colour? Tried to delete.

 

## Page
<?php $found = GetColur($MyBalls,$rsLottoList['N1']); ?>
<td style="text-align:right"><?=$rsLottoList['N1']?></td>

## Code
function GetColur($Balls,$Ball)
{
	$found = 0;
	for($a = 0;$a <5; $a++)
	{
		if($Balls[$a] == $Ball)
			$found = 1;
	}
	return $found;
}

 

Edited by Paul-D

Alternative approach...

<?php

$winners = [ 'norm' => [1,23,27,36,48],
             'stars' => [8,12]
           ];
           
$myNums  = [ 'norm' => [1,3,27,38,48],
             'stars' => [7,12]
           ];
$normCorrect = count(array_intersect($winners['norm'], $myNums['norm']));
$starsCorrect = count(array_intersect($winners['stars'], $myNums['stars']));

$results = sprintf ("\n%-15s%3d\n%-15s%3d", 'Normal', $normCorrect, 'Lucky Stars', $starsCorrect);

$balls = '';

foreach ($myNums['norm'] as $b)  {
    $bno = str_pad($b, 2, '0', STR_PAD_LEFT);
    $cls = (in_array($b, $winners['norm'])) ? 'match' : 'nomatch';
    $balls .= "<div class='ball $cls'>$bno</div>";
}

$balls .= '<br>';

foreach ($myNums['stars'] as $b)  {
    $bno = str_pad($b, 2, '0', STR_PAD_LEFT);
    $cls = (in_array($b, $winners['stars'])) ? 'matchstar' : 'nomatchstar';
    $balls .= "<div class='ball $cls'>$bno</div>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example</title>
    <meta charset="utf-8">
    <style type='text/css'>
        body {
            font-family: verdana, arial, sans-serif;
            font-size: 12pt;
        }
        .ball {
            width: 40px;
            height: 40px;
            clip-path: circle(40%);
            text-align: center;
            display: inline-block;
            padding-top: 18px;
            margin: 5px;
        }
        .nomatch {
            background-color: #000000;
            color: #FFFFFF;
        }
        .nomatchstar {
            background-color: #808080;
            color: #FFFFFF;
        }
        .match {
            background-color: #006EFC;
            color: #FFFFFF;
        }
        .matchstar {
            background-color: #EEEE18;
            color: #000000;
        }
    </style>
</head>
<body>
    <div>
        <h3>Results</h3>
        <pre>
            <?= $results ?>
        </pre>
            <?= $balls ?>
    </div>
</body>
</html>

image.png.58562c5f704d232052f7140b524cfa4b.png

Posted (edited)

I realise that there are other ways of doing this but I can't rip it up now and start again. I have a system which has worked for years. I need to work out why I am not getting a match in... I have tested the values in the function and they are correct. I am getting back #c53ba1 in all the returns.

function GetColour($Balls,$Ball)
{
    $found = "#c53ba1";
    for($a = 0;$a <5; $a++)
    {
        if($Balls[$a] == $Ball)            
            $found == "#0000ff";
    }
    return $found;
}

Edited by Paul-D
On 7/16/2024 at 6:01 PM, Paul-D said:

Thanks. Stupid mistake to make.

common mistake, actually. Happens to everyone somewhere along the line.

However, ignoring Barand's advice is probably more of a stupid mistake because it is more efficient and logical.

	function GetColour($Balls, $Ball) {
  return in_array($Ball, $Balls) ? '#0000ff': '#c53ba1';
}
	echo GetColour([01, 03, 27, 38, 48, 07, 12], 27) . ' = 27<br>';
echo GetColour([01, 03, 27, 38, 48, 07, 12], 73) . ' = 73';
	

sorry, folks: As an American born person, I prefer the stars and stripes spelling of color[-s] over the French spelling. It drives me nuts sometimes. I can excuse the British Barand but knock it off already. 🙂 LOL

Honestly. Barand is a pro and that is some good pro advice for you to follow.

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.