Helping Roumlus to stop his prof calling him a noob tomorrow :D  (Read 8809 times)

hellfire

  • Sr. Member
  • *
  • Posts: 236
  • Country: fr
  • Dev, gamer, entrepreneur, good hearted&mock raging
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 ;)

hellfire

  • Sr. Member
  • *
  • Posts: 236
  • Country: fr
  • Dev, gamer, entrepreneur, good hearted&mock raging
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 ;)

Romulus

  • 1337
  • *
  • Posts: 301
  • Country: hu
  • ❤️JL❤️
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



this is my code:
Code: [Select]
<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] == );
            
$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>

Romulus

  • 1337
  • *
  • Posts: 301
  • Country: hu
  • ❤️JL❤️
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.
« Last Edit: April 21, 2022, 16:47 by Romulus »

hellfire

  • Sr. Member
  • *
  • Posts: 236
  • Country: fr
  • Dev, gamer, entrepreneur, good hearted&mock raging
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?

-Adler-

  • Junior Member
  • *
  • Posts: 45
  • Country: 00
-----------------------------------------------------------------
Sorry, but I don't trust anything that bleeds for five days and doesn't die.

Yes

  • Newbie
  • *
  • Posts: 2
  • Country: gb
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


Code: [Select]
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:

Code: [Select]
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)

  • $table to serve as the output - this wasn't really nessessary tbh but I couldn't be bothered replacing it. Can replace the $table.= with your prints again if needbe
  • Closed your td cell; most browsers help with this anyway but good to know -> $table.="</td></font>";
  • Replaced your  if($tipp[1]==$i || $tipp[2]==$i  || $tipp[3]==$i || $tipp[4]==$i || $tipp[5]==$i) with if(in_array($i, $tipp)){ - check here for details: https://www.w3schools.com/php/func_array_in_array.asp but tl;dr it'll just check if I is in your tipp array
  • Then the main part, from what it sounded like you only wanted it red in the first 5 so I just whacked an if/else inside if($tomb[$i] == 1){
                   $table.="<td bgcolor=\"#FF0000\">";
                   }
                   else{
                
                        $table.="<td bgcolor=\"#47FF00\">";
                   }

Gives you something like



Romulus

  • 1337
  • *
  • Posts: 301
  • Country: hu
  • ❤️JL❤️
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



« Last Edit: April 21, 2022, 18:22 by Romulus »

-Adler-

  • Junior Member
  • *
  • Posts: 45
  • Country: 00
https://pastebin.com/URfWjXJf


bell spark mips test

//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);
-----------------------------------------------------------------
Sorry, but I don't trust anything that bleeds for five days and doesn't die.

Romulus

  • 1337
  • *
  • Posts: 301
  • Country: hu
  • ❤️JL❤️
.
« Last Edit: May 04, 2022, 12:39 by Romulus »

hellfire

  • Sr. Member
  • *
  • Posts: 236
  • Country: fr
  • Dev, gamer, entrepreneur, good hearted&mock raging
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

-Adler-

  • Junior Member
  • *
  • Posts: 45
  • Country: 00
https://www.php.net/manual/en/language.variables.scope.php
i extended the examples here...
Code: [Select]
<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 */
?>

-----------------------------------------------------------------
Sorry, but I don't trust anything that bleeds for five days and doesn't die.

Romulus

  • 1337
  • *
  • Posts: 301
  • Country: hu
  • ❤️JL❤️
i extended the examples here...
Thank you very much!!!
« Last Edit: May 04, 2022, 12:39 by Romulus »

Romulus

  • 1337
  • *
  • Posts: 301
  • Country: hu
  • ❤️JL❤️
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!
« Last Edit: May 04, 2022, 12:39 by Romulus »

-Adler-

  • Junior Member
  • *
  • Posts: 45
  • Country: 00
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.
« Last Edit: April 22, 2022, 15:06 by -Adler- »
-----------------------------------------------------------------
Sorry, but I don't trust anything that bleeds for five days and doesn't die.