hi, trying to brush up on my ( pretty poor ) php skills. Just messing about so i thought i'd write a lottery number checker. you enter your 6 numbers into an html form which then uses php to check against a mysql db. The mysql query returns any row from the db where at least 1 number appears, ( which is what i want ) but i also want to highlight any rows that contain at least 3 of the numbers from the form
so the mysql table contains 8 columns ( the 6 draw numbers plus bonus ball and draw date )
the actual query works fine so i won't waste space here
what i'm trying to acheive is something like:
sudo code
while ($row = mysql_fetch_array($query)){
if(when we compare the balls from the form against $row, if >= 3 then $banner='winner' else '$banner='unlucky';
echo "<tr><td align='center' bgcolor='$color'>";
echo $row['0'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['1'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['2'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['3'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['4'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['5'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['6'];
echo "</td><td align='center' bgcolor='$color'>";
echo $row['7'];
echo "</td><td>$banner";
echo "</td></tr>";
}
i know that if i search $row all is fine, if i do:
foreach($ballArray as $ball){ // $ballArray being the array from the form
if (in_array("$ball",$row)){
echo "<b>$ball IS IN ARRAY</b></br>"; }else{ echo "$ball is not in array</br>";};
}
i get the correct output but if i do something like
foreach($ballArray as $ball){
if (in_array("$ball",$row)){ $banner='winner'; }else{ $banner='unlucky'; };
}
only the last statement seems to get returned so even if there are 1 or more numbers the 'unlucky' banner gets returned.
been banging my head with this for a few days now, i've tried all sorts of array functions, so not sure if it's as easy as i thought, but any pointers would be appreciated.