Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. try echo '<pre>' . print_r($_SESSION, true) . '</pre>'; That will show the contents of $_SESSION. If it's doesn't contain the expected values you need to trace backwards to where the values should be set and work out why it isn't happening.
  2. Have you checked if $_SESSION contains what you are expecting it to contain?
  3. Can you post the output from SHOW CREATE TABLE ip_lookup; and SHOW CREATE TABLE download;
  4. Use json_decode() to create either an object or array. You can then access the individual elements.
  5. You could replace $myfile = fopen("test.txt", "r") or die("Unable to open file!"); while(!feof($myfile)) { $text[] = fgets($myfile); } fclose($myfile); with $text = file('test.txt', FILE_IGNORE_NEW_LINES);
  6. Barand

    Kevin

    ... and a meaningful topic title
  7. Remove the ( ) from the SELECT clause. download +----+---------------------+------------+----------+ | ID | LOG_TIME | IP_ADDRESS | FILENAME | +----+---------------------+------------+----------+ | 1 | 2020-05-03 17:26:56 | 20 | NULL | | 2 | 2020-05-03 17:26:56 | 160 | a.txt | | 3 | 2020-05-03 17:26:56 | 205 | b.txt | +----+---------------------+------------+----------+ ip_lookup +-------+----------+--------+---------+--------+------------+ | IP_ID | start_ip | end_ip | country | area | city | +-------+----------+--------+---------+--------+------------+ | 1 | 1 | 100 | USA | NY | New York | | 2 | 101 | 200 | UK | N West | Manchester | | 3 | 201 | 300 | Spain | North | Barcelona | +-------+----------+--------+---------+--------+------------+ mysql> SELECT download.FILENAME, ip_lookup.country, ip_lookup.area, ip_lookup.city -> FROM download, ip_lookup -> WHERE download.IP_ADDRESS BETWEEN ip_lookup.start_ip and ip_lookup.end_ip; +----------+---------+--------+------------+ | FILENAME | country | area | city | +----------+---------+--------+------------+ | NULL | USA | NY | New York | | a.txt | UK | N West | Manchester | | b.txt | Spain | North | Barcelona | +----------+---------+--------+------------+ Also, use explicit join syntax and not "FROM A,B WHERE ..." SELECT download.FILENAME , ip_lookup.country , ip_lookup.area , ip_lookup.city FROM download INNER JOIN ip_lookup ON download.IP_ADDRESS BETWEEN ip_lookup.start_ip and ip_lookup.end_ip;
  8. Why do you feel this urge to duplicate the country, area,city data? You only need it in the ip_lookup table. Join the two tables in a query whenever you want that info for access table records.
  9. One of the reasons for using an http request (AJAX) is to stay on the same page. If you want output to go to another page use a link or a form with GET or POST and send to the other page.
  10. The var_dump() output has now shown you why - the values are not the same. You search for "charlie" but array contains "charlie\n"
  11. No. PHP knows nothing about where the page should appear, it is running remotely on the server. Things like opening new tabs need to be handled on the client, using HTML or JavaScript.
  12. Does a var_dump() of $word and $text[2] reveal any differences?
  13. Start by following those two links that @requinix included for you in his reply.
  14. Unlikely Quotes need removing... $query = "UPDATE `greencard` SET `comments`= '$comments', 'sent' = '$sent' WHERE `hospitalnumber`= '$hospitalnumber' and `PIN`= '$PIN'"; ^ ^ and it's easier just to use ... sent = NOW() WHERE ...
  15. 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.
  16. Yes $a = new DateTime('2020-05-01'); $b = new DateTime('2020-05-04'); echo $a->diff($b)->days; //-> 3
  17. You appear to be duplicating the city in most tables
  18. Yet you still do it, which is why I have given up.
  19. Barand

    extract text

    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
  20. Barand

    extract text

    As you just post a problem then disappear with acknowledging any replies, why should we waste our time?
  21. 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>
  22. 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) ;
  23. What error messages are you getting?
  24. 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]' >
  25. 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>
×
×
  • 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.