Miasma Community

General Zone => The Lounge => Topic started by: hellfire on April 21, 2022, 16:08

Title: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: hellfire on April 21, 2022, 16:08
Yo,

Story: Romulus cannot play unreal as his deadline for a code is tomorrow and hence we are missing the deemer scares in base. Lets help him debug :D

Post your problem in here so 100 brains can work together. I do not read Hungarian and so your variable names are not making sense and also you used blue.

In short,

1. Can you run the script and inspect it to show the HTML output. If the output is showing the colour we will know something atleast. I quickly checked escape character issues but the best way is to run it in local host to debug. To help others, can you please show the output html after code is run.

Thanks ;)
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: hellfire on April 21, 2022, 16:15
Very quickly since I am at work:

1. Run your script here : https://sandbox.onlinephpfunctions.com/

2. Run output here : https://codebeautify.org/htmlviewer

In link 2, basic HTML errors are highlighted. This way you can quickly check if the error is format error vs logic error in the php. Let me know ;)
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 21, 2022, 16:20
Thank you @Hellfire

" kihúzott szám " =
" kihúzott szám " =
" kihúzott szám " =
" kihúzott szám " =
" kihúzott szám " =

English:
"drawn number"=
"drawn number"=
"drawn number"=
"drawn number"=
"drawn number"=

as you can see in the picture ... the number 4 is included in the solution ... and I would like the number 4 in the table to change to red when it is among the randomly generated numbers ... and so is 1, 2, 3,4,5 numbers .... their base color is green ... and if it's listed above for random generated numbers then switch from green to red ... I need specific help...everything help I appreciate .... I don't ask for help often because I want to improve myself, but I really need a specialist now...  :(

https://ibb.co/1K8LR3p
(https://i.ibb.co/92sNyJf/2022-04-21-2.png) (https://ibb.co/1K8LR3p)


this is my code:
<html>
<head>
<title>Lottó</title>
</head>
<body>

<center>
<form name="lotto" action="index.php" method="POST">
<h1><u>Lottó</u> &nbsp;
<input type="submit" name="ujra" value="Újra" />
</h1>
</form>

<?php
$tipp
=array(0,1,2,3,4,5);
function
kepre($tomb){
$tipp=array(0,1,2,3,4,5);
           print
"<table border=\"2\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" >\n";
           for (
$i=1; $i<91; $i++)
           {
               print
"<font size=\"6\">";
               if(
$tipp[1]==$i || $tipp[2]==$i  || $tipp[3]==$i || $tipp[4]==$i || $tipp[5]==$i)
                   print
"<td bgcolor=\"#47FF00\">";
               else
                   print
"<td bgcolor=\"#eeeeee\">";
               print
$i;
               print
"</font>";
               if(
$i%15==0)
               {
                   print
"<tr>\n";
               }
           }      
           print
"</table>\n";
           return
true;
}
$tomb = array();
//tömbfeltöltés
for ($i=1; $i<=90; $i++){
           
$tomb[$i] = 0;
}
//lottóhúzás
for ($i=1; $i<=5; $i++){
           do{
                 
$v = rand(1,90);
           }while (
$tomb[$v] == 1 );
           
$tomb[$v] = 1;
           
$t[$i]=$v;
}

print
"A nyerőszámok a következőek: <br />";
for (
$i=1; $i<6; $i++)
{
echo
$i.". kihúzott szám: ".$t[$i]."<br />";
}

print
"Az általam tippelt nyerőszámok a következőek: <br />";
for (
$i=1; $i<6; $i++)
{
echo
$i.". tippelt szám: ".$tipp[$i]."<br />";
}

kepre($tomb);
?>
</center>
</body>
</html>
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 21, 2022, 16:24
Quote from: hellfire on April 21, 2022, 16:15
Very quickly since I am at work:

1. Run your script here : https://sandbox.onlinephpfunctions.com/

2. Run output here : https://codebeautify.org/htmlviewer

In link 2, basic HTML errors are highlighted. This way you can quickly check if the error is format error vs logic error in the php. Let me know ;)

actually yes, the deadline expires today, but i did my job ... my teacher is very pleased with my diligence ...
i couldn't incorporate this one function alone ...

there are still new things for me ... I only started learning computer science about half a year ago ...
i am just very curious to solve this task .... i would be very interested ... i searched the net for several days but unfortunately i didn't find anything useful ... i tried many code variations but unfortunately it failed.
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: hellfire on April 21, 2022, 17:31
Can you use a css class and check if the code works with that. Eg: If number ==4,  print "<td bgcolor=\"#47FF00\">" is not good coding as bgcolour will probably be depreciated soon? Instead, why not assign a class and define the class separately in a css file. In short, try doing this using css and let me know results.

Eg: echo '<td class="HellFireRocks">something</p>';

.HellFireRocks {
    color: red;
}

you get the idea?
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: -Adler- on April 21, 2022, 18:06
https://pastebin.com/URfWjXJf

(https://i.ibb.co/KVMsSnP/Screenshot-2022-04-21-at-19-04-37-Lott.png) (https://ibb.co/ygwk729)
bell spark mips test (https://imgbb.com/)
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Yes on April 21, 2022, 18:07
Hi All,

Got bored took a look

CSS classes would be best practise but aren't fully nessesary if you don't want to

I've made a function that I THINK does what your looking for


function kepre($tomb){
$tipp=array(0,1,2,3,4,5);
$table = "";

//print_r($tomb); use this to print

            $table.="<table border=\"2\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" >\n";
            for ($i=1; $i<91; $i++)
            {
                $table.="<font size=\"6\">";

                if(in_array($i, $tipp)){
//echo "i be: $i";
if($tomb[$i] == 1){
$table.="<td bgcolor=\"#FF0000\">";
}
else{

                    $table.="<td bgcolor=\"#47FF00\">";
}
}
                else
                    $table.="<td bgcolor=\"#eeeeee\">";
                $table.=$i;
                $table.="</td></font>"; // never closed your td tag
                if($i%15==0)
                {
                    $table.="<tr>\n";
                }
            }     
            $table.="</table>\n";

echo $table;
            return true;
}


I got confused at first so the $table syntax probably isn't needed

Effectivelly though $tomb ended up being something like this:

Array ( [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 [21] => 0 [22] => 0 [23] => 0 [24] => 0 [25] => 0 [26] => 1 [27] => 0 [28] => 0 [29] => 0 [30] => 0 [31] => 0 [32] => 1 [33] => 0 [34] => 0 [35] => 0 [36] => 1 [37] => 0 [38] => 0 [39] => 0 [40] => 0 [41] => 0 [42] => 0 [43] => 0 [44] => 0 [45] => 0 [46] => 0 [47] => 0 [48] => 0 [49] => 0 [50] => 0 [51] => 0 [52] => 0 [53] => 0 [54] => 0 [55] => 0 [56] => 0 [57] => 0 [58] => 0 [59] => 0 [60] => 0 [61] => 0 [62] => 0 [63] => 0 [64] => 0 [65] => 0 [66] => 0 [67] => 0 [68] => 0 [69] => 0 [70] => 0 [71] => 0 [72] => 0 [73] => 0 [74] => 0 [75] => 1 [76] => 0 [77] => 0 [78] => 0 [79] => 0 [80] => 1 [81] => 0 [82] => 0 [83] => 0 [84] => 0 [85] => 0 [86] => 0 [87] => 0 [88] => 0 [89] => 0 [90] => 0 )


So e.g. 26 in this example was 1 meaning it was one of your numbers

All you really have to do is compare that in your loop and print out accordingly

So basically in terms of the changes I made (didn't need too many)


Gives you something like (https://media.discordapp.net/attachments/384331350406070274/966735204100243466/unknown.png?width=870&height=469)


Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 21, 2022, 18:16
Okay......redesign ...
I'm done with so many minor errors that I ask for the numbers and the machine doesn't generate a random 5 number ... but whichever number I'm guessing will be red ... see the picture.

https://ibb.co/SvnyxMs
https://ibb.co/XFYPQhq

(https://i.ibb.co/Y8M5N6q/2022-04-21-10.png) (https://ibb.co/ft53XbP)

(https://i.ibb.co/PcS6Gxj/2022-04-21-11.png) (https://ibb.co/c6mrhJ3)
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: -Adler- on April 21, 2022, 18:28
https://pastebin.com/URfWjXJf

(https://i.ibb.co/KVMsSnP/Screenshot-2022-04-21-at-19-04-37-Lott.png) (https://ibb.co/ygwk729)
bell spark mips test (https://imgbb.com/)

//VARS

$MyLottoTipp = array(1,10,20,30,40,50);

$LottoRandomNumbers = generateRandom();

echo '<h2>Lotto-Numbers</h2>';
displayLottoList($LottoRandomNumbers,'Number: ');
echo '<h2>Lotto-Tipps</h2>';
displayLottoList($MyLottoTipp,'Tipp: ');
displayLottoTable($LottoRandomNumbers,$MyLottoTipp);
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 21, 2022, 18:42
.
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: hellfire on April 21, 2022, 21:58
Glad you got the help needed :) I just finished another round of work (after evening gaming) and took a look here and this is the power of teamwork hehe.  I have to make up contracts and model stuff up for strategy. So, wine + number crunching all weekend /week. So, sorry I could not help more before but wonderful to see the rest pitch in :)

Just 1 note: Start writing comments in your code from early on. A good coder always comments so that everyone can work rapidly. Anyway you will soon git your life away lol
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: -Adler- on April 22, 2022, 00:49
https://www.php.net/manual/en/language.variables.scope.php (https://www.php.net/manual/en/language.variables.scope.php)
i extended the examples here...

<p>scope. For example:</p>
<?php
$a
= 1; /* global scope */

function test()
{
   echo
$a; /* reference to local scope variable */
}

test();
?>

<p>This script will not produce any output because the echo statement refers to a local version of the $a variable, and it has not been assigned a value within this scope. You may notice that this is a little bit different from the C language in that global variables in C are automatically available to functions unless specifically overridden by a local definition. This can cause some problems in that people may inadvertently change a global variable. In PHP global variables must be declared global inside a function if they are going to be used in that function.
</p>

<p>example 2</p>
<?php
$a
= 1; /* global scope */

function testb($parametera)
{
   echo
$parametera; /* output 1 */
}

testb($a);
?>

<p>example 3</p>
<?php
$a
= 1; /* global scope */

function testc($a = 2)
{
   echo
$a; /* output 2 */
}

testc();
?>


<p>example 4</p>
<?php
$a
= 1; /* global scope */

function testd($a)
{
   echo
$a; /* output 1 */
   
echo '<p></p> ';
   
$a = $a + 5;
   echo
$a;/* output 6 */
}

testd($a);
echo
'<p></p> ';

echo
$a; /* output 1 */
?>


<p>example 5 return</p>
<?php
$a
= 1; /* global scope */

function teste($a)
{
   
   
$a = $a + 5;
   return
$a;/* return 6 */
}
echo
$a;/* output 1 */
$a = teste($a); /* returned value 6*/
echo '<p></p> ';
echo
$a; /* output 6 */
?>
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 22, 2022, 04:45
Quote from: -Adler- on April 22, 2022, 00:49
i extended the examples here...
Thank you very much!!!
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 22, 2022, 04:48
Quote from: hellfire on April 21, 2022, 21:58
Glad you got the help needed :)
I was really glad I got so many versions! Surprised me! I didn't expect anyone to help me ... thank you so much for the many valuable answers to everyone!
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: -Adler- on April 22, 2022, 14:58
I'm writing my own little CMS (Content Management System) for myself and my local sports club and IT junkies site... 5min analysis of the question and translation into English German. Comments are helpful.
   I wrote the code in 5 minutes. But keep it simple so you understand. (Input Output -> Result). I saw your redesigned form. Always validate user input is the first rule. The second rule is to check if you are also entering a number or text... or a time... for a later database query...
They're also a great way to learn, but programming isn't everything. Different end devices and systems must also be taken into account.
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 22, 2022, 17:38
.
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 22, 2022, 17:40
.
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: -Adler- on April 23, 2022, 11:10
yellow color hurts my eyes :D
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 23, 2022, 11:23
 I'll change than
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 23, 2022, 11:24
Thank you so much for your help
Title: Re: Helping Roumlus to stop his prof calling him a noob tomorrow :D
Post by: Romulus on April 26, 2022, 05:45
.