Jump to content

Barand

Moderators
  • Content Count

    19,376
  • Joined

  • Last visited

  • Days Won

    381

Everything posted by Barand

  1. That would require us knowing where you want to go. We can help you more if you explain exactly what this process should accomplish and what your database tables look like.
  2. Why are you permitting multiple selections? How many memberships does a person want? What if a member renewed his subscription on or prior to that date - you would still show them as a non-member. I you run it with that same renewal date on the day after that renewal date then they will be back to their original status. Why are you preparing a statement with no parameter placeholders? Your code is very repetetive - use a function EG function membershipOptions ($renewal, $currentStatus) { $renew = new DateTime($renewal); $today = (new DateTime())->setTime(0,0,0); if ($today == $renew) $currentStatus = 'Non-member'; $memberStati = ['Full Member', 'Social Member', 'Non-member']; $opts = ''; foreach ($memberStati as $stat) { $sel = $stat==$currentStatus ? 'selected' : ''; $opts .= "<option $sel>$stat</option>"; } return $opts; }
  3. Is the date the same "Year End" for all players or is it different for each player depending on their renewal date?
  4. You have corrected the syntax error. Does it work? I have no way of knowing what your variables contain or what your custom methods are returning, therefore cannot comment further.
  5. It won't throw an error, just a notice, so it will depend on the error reporting level. Notice: Use of undefined constant cart_qty It will assume it is the string value 'cart_qty'.
  6. That's only one of the problems. What is "$query = ... " there for? You don't use it. "test2" and "test4" are string values so should be quoted in the WHERE clause. (test1 = 'test2' AND test3 = 'test4'). Yours is only correct for numeric values. Your method should return the result, not echo it. [edit] You will probably hit further problems if you have a mix of bind values (AND/OR)
  7. You can see if "secure_file_priv" is set, and what its directory value is (if it is set) with SELECT @@secure_file_priv; Is your mysql server on the same pc as that E drive? (The recommended place for image storage is the server's file system and store its location and other metadata in the database)
  8. That answers the "how" question, but have we answered your original question, viz. "Why isn't it able to find the max value if it's less than 5?"
  9. Instead of ... ob_start(); $stmt->debugDumpParams(); $sql = ob_get_contents(); ob_end_clean(); //$sql = strtok(substr($sql, strpos($sql, '] ')+2), "\n"); $start=strpos($sql, '] ')+2; $sql = substr($sql, $start, strpos($sql, "\nParams:") - $start); why don't you use ... $sql = $stmt->queryString;
  10. That way is far too easy.😄 (In defence of my method, it would enable the extraction of all contest/category winners with a single query)
  11. I can't see your data but one possible explanation is that you have a situation like this mysql> select * from contest_entries; +----------+------------+-------------+---------+-------+----------+ | entry_id | contest_id | category_id | user_id | votes | e_status | +----------+------------+-------------+---------+-------+----------+ | 1 | 5 | 8 | 101 | 2 | 0 | | 2 | 5 | 8 | 102 | 3 | 0 | | 3 | 5 | 8 | 103 | 4 | 0 | | 4 | 1 | 9 | 104 | 1 | 0 | | 5 | 1 | 9 | 105 | 3 | 0 | | 6 | 1 | 9 | 106 | 5 | 0 | +----------+------------+-------------+---------+-------+----------+ The MAX(votes) is 5, but that was in contest 1, category 9. Your query for contest 5 therefore returns no match. mysql> SELECT entry_id -> , user_id -> , votes -> FROM contest_entries -> WHERE contest_id = 5 -> AND category_id = 8 -> AND e_status = 0 -> AND votes = (SELECT MAX(votes) FROM contest_entries) -> LIMIT 1; Empty set (0.00 sec) Possible solution... SELECT entry_id , user_id , votes FROM contest_entries c JOIN ( SELECT contest_id , category_id , MAX(votes) as votes FROM contest_entries GROUP BY contest_id, category_id ) mx USING (contest_id, category_id, votes) WHERE contest_id = 5 AND category_id = 8 AND e_status = 0 LIMIT 1; +----------+---------+-------+ | entry_id | user_id | votes | +----------+---------+-------+ | 3 | 103 | 4 | +----------+---------+-------+
  12. Just my 0.02 worth ... 1. It is always a bad idea to place values provided by the user ($_GET, $_POST, $_COOKIE) directly into your SQL. A better way is this, which avoids doing that and also checks that only valid column names can be used $sort = $_GET['sort'] ?? ''; switch ($sort) { case 'recd_date': $orderby = 'location, recd_date, name'; break; case 'sent_date': $orderby = 'location, sent_date, name'; break; case 'birth_date': $orderby = 'location, birth_date, name'; break; default: $orderby = 'location, name'; break; } 2. Use prepared statements to place values into your query $result = $db->prepare("SELECT * FROM $company WHERE member = ? ORDER BY $orderby "); $result->bind_param('i', $member_number[$i]); $result->execute(); 3. The use of that [$i] index - are you running the query in a loop for different member_numbers? Don't. 4. You have a variable table name ($company) which suggests you have several tables, each for a different company. Better to have a single table and add an indexed "company" column.
  13. Have you checked what "$sort" contains when it isn't working?
  14. The comma, though not required, was OK. It was an array separator and not a statement terminator.
  15. Perhaps you you could ask the API providers to present a more user-friendly interface using JSON EG {"action":"Added","quantity":"1","item_code":"RNA1","product_name":"Mens organic T-Shirt","colour":"white","size":"XL"}
  16. It's the first element in the array. $str = $arr[0];
  17. explode() the string on the ";" to get 6 sections, then explode() each section on the ":" to get get keys and values
  18. What is the code that is giving you the $arr variable in that format in the first place?
  19. Are you calling "session_start()" at the beginning of the second page? +1
  20. Is this close to what you want? $a = json_decode($json, 1); $new = []; foreach ($a['table6'] as $k => $v) { if (array_filter($v)) $new[$k] = $a['table6'][$k]; }
  21. As the comment in the code says - if URL is blank it calls itself.
  22. How should I know? That's your first mention of a startPublishing() function. The code I posted is a functioning, stand-alone script. Do with it what you want.
  23. Try this <?php require 'db_inc.php'; $db = pdoConnect('test'); /*** INITIALISE TABLE - only required once *********************************************************** $db->exec("CREATE TABLE IF NOT EXISTS broadcast( id int not null primary key, streamid varchar(20)) "); $db->exec("INSERT IGNORE INTO broadcast VALUES (1, '0')"); */ // // HAS AN AJAX POST BEEN SENT? // if (isset($_POST['streamid'])) { try { $stmt = $db->prepare("INSERT INTO broadcast (id, streamid) VALUES (1, ?) ON DUPLICATE KEY UPDATE streamid = VALUES(streamid) "); $stmt->execute( [ $_POST['streamid'] ] ); exit($_POST['streamid']); } catch (Exception $e) { exit("ERROR"); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> function randomToken() { return Math.random().toString(36).substr(2) } $().ready( function() { $("#btnSend").click(function() { var tok = randomToken() $.post ( "", // blank - calls self {"streamid" : tok }, function (resp) { alert(resp) }, "TEXT" ) }) }) </script> </head> <body> <button id="btnSend">Send Stream ID</button> </body> </html>
  24. Not true. Connections are made to a server, not a database. This works just fine. define("HOST",'localhost'); define("USERNAME",'?'); define("PASSWORD",'?'); $db = new PDO("mysql:host=".HOST,USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $res = $db->query("SELECT 7 * 6 "); echo $res ->fetchColumn(); //--> 42 Of course it would fail if I tried to access columns from a table (in an unspecified DB)
×
×
  • 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.