Jump to content

Barand

Moderators
  • Posts

    24,608
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. The first code I gave you goes in the validation page. The second piece of code goes in the form page.
  2. You have to display them on the form. What I showed was the method of getting them back to the first page. For example if (isset($_GET['errors']) && !empty($_GET['srrors']) ) { echo "<div style='padding:16px; background-color: red; color: white'>" . join('<br>', $_GET['errors']) . "</div>\n"; }
  3. Your primary problem is that variables created in page 2 are no longer available when you go back to page 1. You need to send the values to the page and the values need to urlencode()d. Also, put your errors in an array so you notify the user of all errors once instead of continually going to and fro betwen the pages. Happily there is an http_build_query() function that is of great help here. Example <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { // was data sent from the form? $post = array_map('trim', $_POST); // remove unwanted whitespace $errors = []; if ($post['field1'] == '') { $errors[] = '"field1" must have a value'; } if ($post['field2'] == '') { $errors[] = '"field2" must have a value'; } if ($post['field3'] == '') { $errors[] = '"field3" must have a value'; } if ($errors) { // if there were errors, return to the form to inform user $post['errors'] = $errors; // also send the form values back so user doesn't have re-enter all data (sticky form) $qstr = http_build_query($post); header("Location: myform.html?$qstr"); // redirect to form with data and error messages exit; // prevent further processing of this page } // // No errors // so we can // process the // data here // header("Location: myform.html"); // return to a new form } ?> edit: PS Alternatively, do the POST processing at the top of the same page as the form.
  4. https://www.php.net/manual/en/features.file-upload.multiple.php
  5. Not the most straightforward XML structure that I have seen. Try $xml = simplexml_load_file('mydata.xml'); $data = $xml->xpath('//Row[Title="Income"]/Rows/Row[RowType="Row"]'); echo "<pre>"; foreach ($data as $row) { $type = $row->Cells->Cell[0]->Value ; $account = $row->Cells->Cell[0]->Attributes->Attribute->Value; $income = $row->Cells->Cell[1]->Value; printf('%-20s | %-40s | %10.2f<br>', $type, $account, $income); } echo "</pre>"; giving Consulting Income | 98e83040-fa3a-4185-9b9b-a49241e2bb76 | 150.32 Contract Income | 7d05a53d-613d-4eb2-a2fc-dcb6adb80b80 | 11748.96 Engineering Income | 225d8c93-251d-4a0b-9093-201acf69fe50 | 7217.29 Equipment Income | 43f518a6-558f-402a-b22d-317bd64b1566 | 7377.17 Licence Income | 1ff30343-7bb2-4402-bb8f-a0813a7fb59e | 3047.68 Other Income | b447935a-4b37-4f38-a841-fb3ae3b491e0 | 331.06
  6. WHERE MATCH(title) AGAINST ("Meise*" IN BOOLEAN MODE); Using the wildcard character "*" finds both meise and meisen in the above example. Alternatively WHERE MATCH(title) AGAINST ("meise meisen");
  7. Any min/max limits on hours/day/hours per week?
  8. I have been following this topic (I say "following" but that is an exaggeration) and I admit I totally clueless about what the inputs to this process are what the goal of the process is what the rules are to achieve the goal and what the constraints are what T1, T2, shift3, shift4 are Apart from that...
  9. it is a link to the PHP reference manual's section on arrays. Read it.
  10. https://www.php.net/manual/en/language.types.array.php
  11. How many topics do you intend creating for this problem? (there is already one too many).
  12. Sounds a simple problem involving a couple of arrays and a loop. What have you tried so far?
  13. "In general", don't write code which relies on a variable having been previously defined without first defining that variable or checking if the variable has been defined before you attempt to reference it.
  14. I assume this post is just so you can have a rant. If it were a serious request for help then you should have provided some information about the problem, the error message you are receiving and the code that is giving error Then, perhaps, someone can help. BTW, coincidentally, I used the same syntax myself earlier today (though not to that extreme without any regard for where and how the variable are to be used, and I am not happy about that $row[] in there) when setting default input values for a form
  15. Why so much wasted space in topic headings in default theme/grid view ? and, in same grid view using dark theme, grid columns are 100% wide insted of 25%
  16. Barand

    group by

    That's what I thought.
  17. Barand

    group by

    If I am understanding the question correctly, the query to populate Box 1 is SELECT DISTINCT title FROM xmas ORDER BY title; On your page, use an onchange handler to send an AJAX request which sends the title then receives the results of this second query to populate Box 2 SELECT artist FROM xmas WHERE title = ?
  18. I take it that the user->asset relationship is 1 to many, but an asset can only be assigned to one user? Hence two tables. You need somethng like this $q = "SELECT t1.hid , t1.description , t2.name FROM assets t1 LEFT JOIN users t2 ON t1.uid = t2.uid WHERE t1.hid = ? "; (I'll move this to the MySQL forum)
  19. Yes, change the file name from xxx.html to xxx.php.
  20. Most servers are configured so that files with names ending with ".php" are processed by the PHP preprocessor. Unless your server is specifically configured to do so, ".html" files will not be processed and any php code is treated a text.
  21. That is only a problem if you store the "display name" in the list. Store the users' ids (which will be unique and never change) and the problem vanishes. EG +----------------+ +--------------------+ +-------------+ | user | | group_member | | group | +----------------+ +--------------------+ +-------------+ | user_id PK |------+ | group_id |>-----------| group_id PK | | username | +----<| user_id | | group_name | | password | +--------------------+ +-------------+ | display_name | +----------------+
  22. For the record (several user variables, three levels of subquery and a user-defined function later) here is an SQL impementation. The query on it's own, without the function, gave +----------------+----------------+ | my | days | +----------------+----------------+ | May 2005 | 21 | | June 2005 | 22 | | November 2006 | 1-2 | | September 2019 | 28-29-30 | | October 2019 | 1 | | August 2020 | 8 10-11-12 16 | | September 2020 | 20 27-28-29-30 | | October 2020 | 1-2 | +----------------+----------------+ The contiguise() function parses the "days" string, adds commas and removes the inner numbers from the ranges and replaces them with a "-". With the function it gives +----------------+--------------+ | my | days | +----------------+--------------+ | May 2005 | 21 | | June 2005 | 22 | | November 2006 | 1-2 | | September 2019 | 28-30 | | October 2019 | 1 | | August 2020 | 8, 10-12, 16 | | September 2020 | 20, 27-30 | | October 2020 | 1-2 | +----------------+--------------+ QUERY SELECT my , contiguise(REPLACE(GROUP_CONCAT(contig order by dno separator ' '), ' - ', '-')) AS days FROM ( SELECT CASE WHEN dno = @prev + 1 AND my = @prevmy THEN concat('- ',dno) ELSE dno END AS contig , date , @prev := dno AS dno , @prevmy := my AS my FROM ( SELECT DATE_FORMAT(date, '%M %Y') AS my , DAY(date) AS dno , date FROM date ORDER BY date ) pre JOIN (SELECT @prev := -1, @prevmy := '') init ) data GROUP BY my ORDER BY date; FUNCTION DELIMITER $$ CREATE FUNCTION `contiguise`(days varchar(150) ) RETURNS varchar(150) CHARSET utf8 BEGIN DECLARE temp varchar(150) DEFAULT ''; DECLARE result varchar(150) DEFAULT ''; DECLARE pos1 int DEFAULT 1; DECLARE pos2 int DEFAULT 0; WHILE pos1 <= LENGTH(days) DO SET pos2 = LOCATE(' ', days, pos1); IF pos2 = 0 THEN SET pos2 = LENGTH(days)+1; END IF; SET temp = SUBSTRING(days, pos1, pos2 - pos1); IF LOCATE('-', temp) <> 0 THEN SET temp = CONCAT(SUBSTRING_INDEX(temp, '-',1), '-', SUBSTRING_INDEX(temp, '-',-1)); END IF; IF result = '' THEN SET result = temp; ELSE SET result = CONCAT(result, ', ', temp); END IF; SET pos1 = pos2 + 1; END WHILE; RETURN result; END$$ DELIMITER ; TEST DATA +------------+ | date | +------------+ | 2005-05-21 | | 2005-06-22 | | 2006-11-01 | | 2006-11-02 | | 2019-09-28 | | 2019-09-29 | | 2019-09-30 | | 2019-10-01 | | 2020-08-08 | | 2020-08-10 | | 2020-08-11 | | 2020-08-12 | | 2020-08-16 | | 2020-09-20 | | 2020-09-27 | | 2020-09-28 | | 2020-09-29 | | 2020-09-30 | | 2020-10-01 | | 2020-10-02 | +------------+
  23. However, using the string just as far as the the first entity $valrD = json_decode(valrGet, true); echo '<pre>$valrD = ', print_r($valrD, 1), '</pre>'; gives therefore $target = 'BTC/ZAR'; foreach ($valrD['response']['entities'] as $k => $ents) { if ($ents['pair_name'] == $target) { echo "$target asking price : {$ents['ask']['price']}<br>"; break; } } outputs "BTC/ZAR asking price : 179382.54"
  24. Your json has been truncated and therefore invalid.
  25. Ask yourself "Why are you running that query?"
×
×
  • 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.