-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
The best place to set the default timezone is in your php.ini file. Then you don't have to set the default in every script.
-
Yes $a = new DateTime('2020-05-01'); $b = new DateTime('2020-05-04'); echo $a->diff($b)->days; //-> 3
-
You appear to be duplicating the city in most tables
-
Yet you still do it, which is why I have given up.
-
I refer to the last topic you posted here. https://forums.phpfreaks.com/topic/310600-delete-the-whole-sentence-which-contains-two-consecutive-words-beginning-with-large-letters/?do=findComment&comment=1576951
-
As you just post a problem then disappear with acknowledging any replies, why should we waste our time?
-
A friend of mine is also organising bingo sessions so I wrote a script for her, and I am happy to share it here. There are additions I plan to make, such as outputting each players cards in pdf for emailing out before the game storing the cards and numbers called in a DB to facilitate checking when "Bingo!" is called but here is current version which produces this... Code <?php $name = $_GET['name'] ?? ''; $date = $_GET['date'] ?? date('Y-m-d', strtotime("+1 day")); $players = $_GET['players'] ?? '4'; $games = $_GET['games'] ?? '5'; $output = ''; $cards = []; if ($name) { $ranges = [ 0 => range( 1, 9), 1 => range(10, 19), 2 => range(20, 29), 3 => range(30, 39), 4 => range(40, 49), 5 => range(50, 59), 6 => range(60, 69), 7 => range(70, 79), 8 => range(80, 90) ]; if ($nCards = $players * $games) { do { $card = makeCard($ranges); if (!in_array($card, $cards)) { $cards[] = $card; } } while ( count($cards) < $nCards); #echo '<pre>', print_r($cards, 1), '</pre>'; } $output = '<div class="w3-container w3-purple w3-padding w3-margin"><h1>'.$name.'</h1></div>'; $output .= cardOutput($cards, $players, $games); } /** * build html output for the generated cards * * @param array $cards * @param int $players * @param int $games */ function cardOutput($cards, $players, $games) { $cardColors = ['blue', 'green', 'yellow', 'orange', 'red']; $output = ''; $pcards = array_chunk($cards, $games); foreach ($pcards as $pid =>$gcards) { $pno = $pid +1; $output .= "<div class=\"w3-container w3-indigo w3-margin w3-padding\"><h3>Player $pno</h3></div>"; foreach ($gcards as $gid => $gnums) { $clr = $cardColors[$gid % 5]; $gno = $gid + 1; $output .= "<div class='w3-content w3-$clr w3-margin-top'> <table border='1'> <tr><th colspan='9'>Game $gno</th></tr>"; $rows = explode('|', $gnums); foreach ($rows as $rnums) { $nums = explode(',', $rnums); $output .= "<tr>"; foreach ($nums as $n) { $output .= $n!=' ' ? "<td>$n</td>" : "<td class='empty'></td>"; } $output .= "</tr>"; } $output .= "</table> </div> "; } } return $output; } /** * generate random bingo card - 3 rows x 9 columns - 5 numbers per row * * @param array $ranges */ function makeCard($ranges) { $cols = array_keys($ranges); shuffle($cols); $colnums = []; foreach (array_slice($cols,0,6) as $c) { shuffle($ranges[$c]); $colnums[$c] = array_slice($ranges[$c],0,2); sort($colnums[$c]); } foreach (array_slice($cols,-3) as $c) { $colnums[$c][] = $ranges[$c][array_rand($ranges[$c])]; } $krows = [0,0,0]; $rownums = []; $first=1; foreach ($colnums as $c => $nums) { sort($nums); switch (count($nums)) { case 1: if ($first) { $r = rand(0,2); } else { $r = shortestRow($krows); } $first = 0; $krows[$r]++; $rownums[$r][$c] = $nums[0]; break; default: $check = []; foreach ($nums as $n) { $r = shortestRow($krows); $krows[$r]++; $rownums[$r][$c] = $n; $check[] = [$r,$n]; } // are col numbers in asc sequence? if ( ($check[0][0] < $check[1][0] && $check[0][1] > $check[1][1]) || ($check[0][0] > $check[1][0] && $check[0][1] < $check[1][1]) ) { // swap numbers $rownums[$check[0][0]][$c] = $check[1][1]; $rownums[$check[1][0]][$c] = $check[0][1]; } break; } } $rows = []; foreach ($rownums as $r => $carr) { $rstr = []; foreach (array_keys($ranges) as $i) { $rstr[] = isset($carr[$i]) ? $carr[$i] : ' '; } $rows[] = join(',',$rstr); } return join("|", $rows); } /** * find row with fewest numbers * * @param array $krows row counts */ function shortestRow($krows) { $n = min($krows); foreach ($krows as $r => $k) { if ($k==$n) return $r; } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Bingo Setup</title> <meta name="author" content="Barand"> <meta name="creation-date" content="04/26/2020"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <style type="text/css"> table { width: 100%; border-collapse: collapse; border-color: #FFF; } td { background-color: #FFF; color: #000; margin: 5px; text-align: center; font-size: 12pt; font-weight: 600; width: 11%; } td.empty { background-color: #F8F8F8; } </style> </head> <body> <header class="w3-container w3-green"> <h1>Bingo Game Setup</h1> </header> <div class="w3-content w3-round-large w3-border w3-margin-top w3-padding w3-sand"> <form> <div class="w3-row"> <label class="w3-third">Your name/group</label> <input type="text" class="w3-input w3-twothird" name="name" value="<?=$name?>"> </div> <div class="w3-row"> <label class="w3-third">Game date</label> <input type="date" class="w3-input w3-twothird" name="date" value='<?=$date?>'> </div> <div class="w3-row"> <label class="w3-third">Number of players</label> <input type="number" class="w3-input w3-twothird" name="players" value='<?=$players?>'> </div> <div class="w3-row"> <label class="w3-third">Number of games</label> <input type="number" class="w3-input w3-twothird" name="games" value='<?=$games?>'> </div> <button class="w3-button w3-blue">Generate game cards</button> </form> </div> <?=$output?> </body> </html>
-
Unless you tell it otherwise, it assumes the csv contains the same fields as the table in the same order. You are not providing data for all the table columns so tell it which columns are present. LOAD DATA LOCAL INFILE '/home/larry/web/test/public_html/dbip-city-lite-2020-04.csv' INTO TABLE ip_lookup FIELDS TERMINATED BY ',' (start_ip, end_ip, continent, country, area, city, latitude, longitude) ;
-
What error messages are you getting?
-
That form is going to be one major headache when it's posted. Use array syntax when naming your fields then processing them is just a loop, <textarea name='sku[$number]' >
-
Try accessing via id <!DOCTYPE> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample</title> <script type="text/javascript"> function changeAmount(a) { var sku = document.getElementById("sku"+a) sku.value = 44 } </script> </head> <body> SKU 999 : <input name='sku999' id='sku999' value = ''><br> <button id='mybtn' onclick='changeAmount(999)'>Set value</button> </body> </html>
-
Just telling us that something "doesn't work" doesn't work.
-
if (form entry is not blank) insert record else don't endif
-
-
The clue was in "ORDER BY"
-
Notice: Trying to get property of non-object in
Barand replied to PythonHelp's topic in PHP Coding Help
The bit that tells you what the function returns, perhaps. -
Can't believe that query produces anything. When you say "grouped by" do you mean "ordered by"? There is a huge difference in SQL between the two.
-
Notice: Trying to get property of non-object in
Barand replied to PythonHelp's topic in PHP Coding Help
It's time to re-read the manual regarding mysqli_fetch_row() -
Notice: Trying to get property of non-object in
Barand replied to PythonHelp's topic in PHP Coding Help
Have you ever considered looking at the manual? https://www.php.net/manual/en/class.mysqli-result.php -
Notice: Trying to get property of non-object in
Barand replied to PythonHelp's topic in PHP Coding Help
"attendance" is a table identifier and should not, therefore, be inside quotes. Quotes are for string literals. -
Notice: Trying to get property of non-object in
Barand replied to PythonHelp's topic in PHP Coding Help
Put this line just before you connect to the mysqli server... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); -
You hope in vain. What have you tried?
-
For $_POST['Att_date'] to exist you need a form input field with that name. The only one I see is 'Presence' Hard to tell with your complete lack of indentation, but it looks like you start a new form for every table row but only have one end-of-form tag at the end.
-
Why are you trying to get your data from print_r() output in the first place?