-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
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.
-
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>';
-
I wonder if there's a Facebook API for that.
-
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 | +------+--------+----------+
-
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.
-
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')";
-
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.
-
try SELECT COUNT( * ) AS total FROM `nem_pae_atividades` WHERE `idutilizador` =1355 AND `data` <= CURDATE( ) AND ( `realizado` IS NULL OR LENGTH( `realizado` )=0 )
-
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)
-
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
-
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"; }
-
Can PHP integrate with microsoft sql by using mysqli?
Barand replied to FooKelvin's topic in MySQL Help
Why do you want to change from sqlsrv if you are still using SQLServer? -
I was using "$m" as an example of a month number variable
-
Can PHP integrate with microsoft sql by using mysqli?
Barand replied to FooKelvin's topic in MySQL Help
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. -
I'd make use of data attributes. <div class='add_more' data-id='$cid' data-month='$m'>
-
How to obtain last id number, to submit in Picasso for App..
Barand replied to dave204's topic in PHP Coding Help
Topics merged. -
Display vs POST info in a mysql based dropdown
Barand replied to itgranny's topic in PHP Coding Help
if you have <option value='$id'>$name</option> then the name is displayed but the id (value) is posted. -
Topics merged
-
@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
-
Your form needs a submit button. Your select has name='site' therefore the value will be in $_POST['site']
-
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>
-
foreach($cars as $a) { $tmp[] = join('||', $a); } $result = join('~', $tmp); echo $result; //--> goat||22||18~pig||15||13~rabbit||5||2~doe||17||15
-
read a cvs file and only displaying some data
Barand replied to manhattes's topic in PHP Coding Help
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. -
use json_decode($json, true); to get an array as the result.
-
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.