Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. You can't nest forms. Your data tables will be 1 to many though, an employee table and a phone table, each row of which contains employee id and a phone number. Just have one form containing employee fields and multiple fields for phone number entry. Name the phone fields something like "phone[]" so they are posted in an array, which you can loop through to process. When processing, insert the employee data and grab the last_insert_id to get the value of the new auto_incremented id field. Use this to insert the emp id value in each of the phone number records.
  2. A somewhat simpler one-liner $input = "dog,white cat,white cat,black cat,white dog,black bird,white"; echo '<pre>',print_r(array_count_values(explode("\n", $input)), true),'</pre>';
  3. I wonder if there's a Facebook API for that.
  4. Just for completeness, an FYI to illustrate the SQL solution mentioned earlier The data mysql> select P_id, Prt_id, Other_id FROM _projecttbl; +------+--------+----------+ | P_id | Prt_id | Other_id | +------+--------+----------+ | 1 | AB | Ghi | | 1 | HG | Fxg | | 1 | CD | Klm | | 2 | qwer | zz | | 2 | asdf | yy | | 2 | ergx | xx | +------+--------+----------+ mysql> select Prt_id, Other_id FROM tempproj; +--------+----------+ | Prt_id | Other_id | +--------+----------+ | AB | Ghi | | ergx | xx | +--------+----------+ The delete query DELETE p FROM _projecttbl p LEFT JOIN tempproj t USING (Prt_id, Other_id) WHERE p.P_id = 1 AND t.Prt_id IS NULL; The result mysql> select P_id, Prt_id, Other_id FROM _projecttbl; +------+--------+----------+ | P_id | Prt_id | Other_id | +------+--------+----------+ | 1 | AB | Ghi | | 2 | qwer | zz | | 2 | asdf | yy | | 2 | ergx | xx | +------+--------+----------+
  5. The error message suggests that $this->connection is not a valid connection object in the failing function. The query in the first function does not need to be a prepared statement - there is no user input. The second function does not require the parameter to be sanitized if you are preparing the statement, You should use a placeholder and bind the parameter to the placeholder. It is the separation of data from query statement that makes preparation effective.
  6. This could work $str = 'HG||Fxg|||ergx||xx'; // replace "|||" with "','" so you have separate records split by quote-comma-quote $str = str_replace("|||", "','", $str); $sql = "DELETE FROM _projecttbl WHERE P_id = 1 AND CONCAT(Prt_id, '||', Oth_id) NOT IN ('$str')";
  7. While you are still working with those silly double-delimited strings of yours, forget about using SQL. Break you string into separate records (Prt_id, Oth_id) and store in a separate db table. Then you can do your deletions by matching the tables.
  8. try SELECT COUNT( * ) AS total FROM `nem_pae_atividades` WHERE `idutilizador` =1355 AND `data` <= CURDATE( ) AND ( `realizado` IS NULL OR LENGTH( `realizado` )=0 )
  9. When mixing AND and OR always use ( )'s to define your logic. For example A AND B OR C Do you mean (A AND B) OR C or A AND (B OR C)
  10. The month number was fetched in the original query. For each course we then created an events array where $m was the key and the value was an array of course dates in that month. if ($sd) $data[$cid]['events'][$m][] = date('j/m/Y', strtotime($sd)); I changed it use the month key and values when looping through the array, instead of just the values. Originally it was foreach ($cdata['events'] as $dates) which I changed to foreach ($cdata['events'] as $m => $dates) so we now had the value for the month that we now needed
  11. I've rewritten this section to use the [$m] in the arrays /********************************************************** * create table from array data ***********************************************************/ foreach ($data as $cid=>$cdata) { $trows .= "<tr><td>$cid</td><td class='cn'>{$cdata['name']}</td>"; foreach ($cdata['events'] as $m => $dates) { $trows .= "<td class='dt'>" . join('<br>', $dates) . "<div class='add_more' data-id='$cid' data-month='$m'>+</div></td>"; } $trows .= "</tr>\n"; }
  12. Why do you want to change from sqlsrv if you are still using SQLServer?
  13. I was using "$m" as an example of a month number variable
  14. No. mysqli_ functions, like mysql_ , are for the MySql database server just as sqlsrv functions are for MS SQL Server. PDO, however, is database independent so you could use that.
  15. I'd make use of data attributes. <div class='add_more' data-id='$cid' data-month='$m'>
  16. if you have <option value='$id'>$name</option> then the name is displayed but the id (value) is posted.
  17. Topics merged
  18. @maxxd, He is intent on doing this way regardless of attempts to advise otherwise http://forums.phpfreaks.com/topic/298429-imploding-a-multi-dimensional-array/?do=findComment&comment=1522337
  19. Your form needs a submit button. Your select has name='site' therefore the value will be in $_POST['site']
  20. use a function which takes an array as its argument. You can then use the same function for sites, people etc by just passing it a different array. <?php $sql1="SELECT Site_ID, Site_name_1 FROM `Sites`"; $result1=mysql_query($sql1); $site_array = array(); while (list($id, $name) = mysql_fetch_row($result1)) { $site_array[$id] = $name; } function get_options($arr, $current=null) { $opts = ''; foreach ($arr as $k => $v) { $sel = $k==$current ? 'selected="selected"' : ''; $opts .= "<option value='k' $sel>$v</option>\n"; } return $opts; } ?> <html> <body> <select name='site'> <?php echo get_options($site_array);?> </select> </body> </html>
  21. foreach($cars as $a) { $tmp[] = join('||', $a); } $result = join('~', $tmp); echo $result; //--> goat||22||18~pig||15||13~rabbit||5||2~doe||17||15
  22. Then why don't you select STR_TO_DATE(completion_date, '%W, %M %d %Y') from your table so you have the format you need. It really is time you converted those dates in your table - it seems to be popping up often in your posts.
  23. use json_decode($json, true); to get an array as the result.
  24. His original query (from opening post) was ... WHERE STR_TO_DATE(`Completion Date`, '%W, %M %e, %Y') BETWEEN CURDATE() AND CURDATE() + INTERVAL (90) DAY which does convert the date string, but contains an error in the BETWEEN clause (ie next 90 days instead of last 90 days). And the output from STR_TO_DATE() mysql> SELECT STR_TO_DATE('Tuesday, October 6 2015', '%W, %M %e %Y') as date; +------------+ | date | +------------+ | 2015-10-06 | +------------+ is definitely yyyy-mm-dd format and is human-readable, contrary to your statement.
×
×
  • 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.