Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 12/23/2018 in all areas

  1. 1 point
    There won't be any "affected rows". It is not an update, delete or insert query.
  2. 1 point
    Oh yes it will try { $db->exec("INSERT INTO units(id, unit) VALUES (1, 'Test')"); // deliberate duplicate } catch (PDOException $e) { echo '<pre>', print_r($e->errorInfo, 1), '</pre>'; } Outputs Array ( [0] => 23000 [1] => 1062 [2] => Duplicate entry '1' for key 'PRIMARY' )
  3. 1 point
    I see a form with no inputs, just a button to submit. Then I see a block of code that builds a query and executes it to insert a record with a static id and static name, neither of which comes from any form. And it happens just once. Despite your poorly written post I'm concerned that you have a poorly designed methodology here as well. And where are these other "quarries" (a place to find rocks?) that you want to have executed as well? From your post I half-expected some kind of input form with values that you then wanted to repeatedly post to a database using a unique key for each. Quite an easy exercise. That was not what you presented.
  4. 1 point
    It appears that you are processing a GEDCOM file. Why not use a GEDCOM parser that has already been developed?
  5. 1 point
    in order to put an array variable inside a string, it needs to be enclosed by {} however, there are a few things wrong with what that line of code is trying to do - 1) the mysqli_query() statement doesn't return data, it returns a result object, so, a variable holding the submitted password will never be equal to the value returned in that line. you would need to fetch the data first. 2) you should NOT store plain-text passwords. you need to use php's password_hash() and password_verify(). you would need to fetch the stored password hash and use password_verify() to test if the submitted password matches the hash. 3) you should NOT put external/unknown data directly into an sql query statement (and for those cases where it is safe to do so, string data must be enclosed by single-quotes.) you instead need to use a prepared query, with a ? place-holder in the sql query statement for each data value, then supply the data when the query gets executed. unfortunately, the php mysqli extension is overly complicated and inconsistent when dealing with prepared queries and you need to switch to the much simpler php PDO extension. doing this will actually simplify the sql query statement since the place-holder being put into the sql query statement eliminates the php variable, any {} around the variable, any single-quotes around the variable, and any concatenation dots.
  6. 1 point
    if (...) { makes the decision about whether to include the item from the XML in the search results. The part inside it needs to be true. stristr(..., ...) What the stristr function is effectively doing is checking if the first argument (a string) contains the second argument (also a string). It doesn't technically return true (or false) like the if expects, but it's close enough that PHP allows it. What you want is not "contains" but "starts with". Unfortunately PHP doesn't have a "starts with" function, but the strncasecmp I linked comes close: it takes two strings and compares the first few characters (you decide how many) to see if they match. The "n" means it compares a length you want, and "case" meaning it's case-insensitive (like the "i" in "stristr" means it's case-insensitive... yeah, one is "case" and one is "i", that's just the way it is). The function returns a number that measures how the two compare, and that number is 0 if they are the same. Since you want "starts with", the length you need to compare is the length of the string you are searching for. "If the first (length of $q) characters are the same...". strlen is the function to get the length. So you need to: - Keep the overall if(...) structure - Use strncasecmp instead of stristr, with the first two arguments being the two strings to compare (it doesn't actually matter which is which) and the third being the length to compare - Use strlen with $q for the length - Check that the strncasecmp function returns a number == 0 Give that a shot, and if you have problems then post what you came up with and a description of what's not working.
  7. 1 point
    I think this is what you are trying to do do { ${$row_Recordset1['bd_variable']} = $row_Recordset1['bd_desc']; } while (...) echo "$company_full_name - $company_small_name"; //--> Some Company Pvt, Ltd - Some Company
  8. 1 point
    Not that I'm aware of. With that said, docker only uses the .env file to set variables that are used during the docker-compose pre-processing stage. You also might be well advised to have some directory structure where your laravel app code is not in the root of the project where it would conflict with docker files. I would also suggest taking a look at how Laradock does things.
  9. 1 point
    Your <option> tags should ech have a correponding </option> closing tag. Your name="MM_Balance should have closing quote. No need to do the months manually: <?php function monthOptions($current) { $opts = ''; $dt1 = new DateTime('2018-01-01'); $dp = new DatePeriod($dt1, new DateInterval('P1M'), 11); foreach ($dp as $d) { $sel = $d->format('m')==$current ? 'selected' : ''; $opts .= sprintf("<option value='%d' $sel>%s</option>\n", $d->format('m'), $d->format('M') ); } return $opts; } ?> <select name="MM_Balance" style="width:60px"> <?=monthOptions(12)?> </select>
  10. 1 point
    How about this? Same table but different (more) data DATA SELECT user_id ,created as date_joined ,GROUP_CONCAT(date_active SEPARATOR ', ') as active_dates FROM user JOIN user_activity using (user_id) GROUP BY user_id +---------+-------------+------------------------------------------------------------------------------------+ | user_id | date_joined | active_dates | +---------+-------------+------------------------------------------------------------------------------------+ | 1 | 2018-05-17 | 2018-05-17, 2018-06-17, 2018-07-17, 2018-08-17, 2018-09-17 | | 2 | 2018-05-24 | 2018-05-24, 2018-06-24, 2018-07-24 | | 3 | 2018-05-09 | 2018-05-09, 2018-06-09 | | 4 | 2018-05-10 | 2018-05-10, 2018-06-10, 2018-07-10, 2018-08-10, 2018-09-10, 2018-10-10, 2018-11-10 | | 5 | 2018-05-10 | 2018-05-10, 2018-06-10 | | 6 | 2018-05-15 | 2018-05-15, 2018-06-15, 2018-07-15, 2018-08-15, 2018-09-15, 2018-10-15, 2018-11-15 | | 7 | 2018-05-03 | 2018-05-03, 2018-06-03, 2018-07-03, 2018-08-03, 2018-09-03, 2018-10-03, 2018-11-03 | | 8 | 2018-05-02 | 2018-05-02, 2018-06-02 | | 9 | 2018-05-27 | 2018-05-27, 2018-06-27, 2018-07-27, 2018-08-27, 2018-09-27, 2018-10-27 | | 10 | 2018-05-23 | 2018-05-23, 2018-06-23, 2018-07-23, 2018-08-23, 2018-09-23, 2018-10-23 | | 11 | 2018-06-04 | 2018-06-04, 2018-07-04, 2018-08-04, 2018-09-04, 2018-10-04, 2018-11-04 | | 12 | 2018-06-17 | 2018-06-17, 2018-07-17, 2018-08-17 | | 13 | 2018-06-14 | 2018-06-14, 2018-07-14, 2018-08-14, 2018-09-14, 2018-10-14, 2018-11-14 | | 14 | 2018-06-26 | 2018-06-26, 2018-07-26 | | 15 | 2018-06-06 | 2018-06-06, 2018-07-06 | | 16 | 2018-06-24 | 2018-06-24, 2018-07-24, 2018-08-24 | | 17 | 2018-06-16 | 2018-06-16, 2018-07-16, 2018-08-16, 2018-09-16, 2018-10-16, 2018-11-16 | | 18 | 2018-06-17 | 2018-06-17, 2018-07-17, 2018-08-17, 2018-09-17, 2018-10-17, 2018-11-17 | | 19 | 2018-06-20 | 2018-06-20, 2018-07-20, 2018-08-20, 2018-09-20 | | 20 | 2018-06-10 | 2018-06-10, 2018-07-10, 2018-08-10, 2018-09-10, 2018-10-10, 2018-11-10 | | 21 | 2018-07-08 | 2018-07-08, 2018-08-08, 2018-09-08 | | 22 | 2018-07-28 | 2018-07-28, 2018-08-28, 2018-09-28, 2018-10-28 | | 23 | 2018-07-12 | 2018-07-12, 2018-08-12, 2018-09-12, 2018-10-12, 2018-11-12 | | 24 | 2018-07-28 | 2018-07-28, 2018-08-28, 2018-09-28, 2018-10-28 | | 25 | 2018-07-06 | 2018-07-06, 2018-08-06 | | 26 | 2018-07-26 | 2018-07-26, 2018-08-26 | | 27 | 2018-07-20 | 2018-07-20, 2018-08-20, 2018-09-20, 2018-10-20, 2018-11-20 | | 28 | 2018-07-09 | 2018-07-09, 2018-08-09 | | 29 | 2018-07-13 | 2018-07-13, 2018-08-13, 2018-09-13, 2018-10-13, 2018-11-13 | | 30 | 2018-07-15 | 2018-07-15, 2018-08-15, 2018-09-15, 2018-10-15, 2018-11-15 | | 31 | 2018-08-12 | 2018-08-12, 2018-09-12, 2018-10-12, 2018-11-12 | | 32 | 2018-08-07 | 2018-08-07, 2018-09-07, 2018-10-07, 2018-11-07 | | 33 | 2018-08-18 | 2018-08-18, 2018-09-18, 2018-10-18, 2018-11-18 | | 34 | 2018-08-15 | 2018-08-15, 2018-09-15, 2018-10-15, 2018-11-15 | | 35 | 2018-08-26 | 2018-08-26, 2018-09-26, 2018-10-26 | | 36 | 2018-08-08 | 2018-08-08, 2018-09-08, 2018-10-08 | | 37 | 2018-08-22 | 2018-08-22, 2018-09-22, 2018-10-22, 2018-11-22 | | 38 | 2018-08-06 | 2018-08-06, 2018-09-06, 2018-10-06, 2018-11-06 | | 39 | 2018-08-01 | 2018-08-01, 2018-09-01 | | 40 | 2018-08-11 | 2018-08-11, 2018-09-11, 2018-10-11 | +---------+-------------+------------------------------------------------------------------------------------+ QUERY SELECT monthname(created) as created , timestampdiff(MONTH, created, date_active) as duration , COUNT(DISTINCT user_id) as user_count FROM user JOIN user_activity USING (user_id) GROUP BY MONTH(created), duration; +--------------+----------+------------+ | created | duration | user_count | +--------------+----------+------------+ | May | 0 | 10 | | May | 1 | 10 | | May | 2 | 7 | | May | 3 | 6 | | May | 4 | 6 | | May | 5 | 5 | | May | 6 | 3 | | June | 0 | 10 | | June | 1 | 10 | | June | 2 | 8 | | June | 3 | 6 | | June | 4 | 5 | | June | 5 | 5 | | July | 0 | 10 | | July | 1 | 10 | | July | 2 | 7 | | July | 3 | 6 | | July | 4 | 4 | | August | 0 | 10 | | August | 1 | 10 | | August | 2 | 9 | | August | 3 | 6 | +--------------+----------+------------+ Using php to run the query and format the output: CODE $res = $db->query("SELECT monthname(created) as created , timestampdiff(MONTH, created, date_active) as duration , COUNT(DISTINCT user_id) as user_count FROM user LEFT JOIN user_activity USING (user_id) WHERE created > CURDATE() - INTERVAL 1 YEAR GROUP BY MONTH(created), duration" ); $data = []; $empty = array_fill_keys(range(0,11), ''); // empty array for each row // // store data in array with same structure as required output // foreach ($res as $rec) { if ( !isset($data[$rec['created']])) { $data[$rec['created']] = $empty; } $data[$rec['created']][$rec['duration']] = $rec['user_count']; } // // generate the table output from the data array // $thead = '<tr><th>Date<br>Created</th>'; foreach (array_keys($empty) as $m) { $thead .= "<th>Month $m</th>"; } $thead .= "</tr>\n"; $tdata = ''; foreach ($data as $month =>$users) { $tdata .= "<tr><td class='month'>$month</td><td>" . join('</td><td>', $users ) . "</td><tr>\n"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Sample</title> <meta name="author" content="Barand"> <meta name="creation-date" content="11/23/2018"> <style type='text/css'> table { font-family: verdana, sans-serif; font-size: 11pt; border-collapse: collapse; } th { background-color: #369; color: white; padding: 5pt; } td { text-align: center; padding: 8px; } td.month { text-align: left; background-color: #C5F8F8; } </style> </head> <body> <table border='1'> <thead><?=$thead?></thead> <tbody><?=$tdata?></tbody> </table> </body> </html> RESULT (I'll leave the pretty gradient colours to you)
This leaderboard is set to New York/GMT-05:00
  • Newsletter

    Want to keep up to date with all our latest news and information?

    Sign Up
×

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.