Validation – Validate duplicate records with Codeigniter

Hello, I use the validation without form_validation library. With ajax I send the modal data and save it. The message for saving is displayed. However, I have to check if they have been duplicated with two fields of the category table. I tried to put the validation method into the model, and then I want to return a message in sight in the controller. Although no duplicates are stored, no duplicate log message is displayed. I attach the script, the controller and the model. Please, I need help … Thank you …

  

// controller ccategoria.php

  public function agregarcat() {

$nombre = $this->input->post('catename');
$idarea = $this->input->post('idarea');
$descrip = $this->input->post('catedesc');
$r = $this->mcategoria->validar($nombre, $idarea);
if ($r == 1) {

    echo "1";

} else {

    $info = array(
        'id_categoria' => '',
        'name' => $nombre,
        'id_area' => $idarea,
        'desc_cat' => $descrip,

    );
    $this->mcategoria->insert($info);

}

}

// There are 2 methods in the model, one valid and the other insert

 public function validar($nombre, $idarea) {
    $select = "id_area, name";
    $this->db->select($select);
    $this->db->from('categorias');
    $this->db->where('categorias.id_area', $idarea);
    $this->db->where('categorias.name', $nombre);
    $consulta = $this->db->get();
    if ($consulta->num_rows() > 0) {
        $r = $consulta->row();
        return 1;
    } else {
        return false;
    }
}

public function insert($data) {

    $this->db->insert('categorias', $data);
}

mysql – How do I get to the top and bottom with multiple records?

I have these records and it is the presence of every employee. I would like to get their participation what I have tried, query is like this, which gets their participation, but if it has a multiple record, it gets the latest participation.
Verify_States stands for 0 = Time in and 1 = Time out

This is the query I tried:

select * from 
(select A.*, 

LEAD(A.Verify_State,1) OVER (PARTITION BY A.user_id 
ORDER BY A.user_id, A.verify_date) as Nxt_row_State, 

LEAD(A.verify_date,1) OVER (PARTITION BY A.user_id 
ORDER BY A.user_id, A.verify_date) as TO_Date 
from tbl_excel_attendance as A ) as tbl_DTR_Mapped 
where tbl_DTR_Mapped.verify_state = 0 and tbl_DTR_Mapped.Nxt_row_State = 1

EDIT: I also tried this query

    Select * from (
SELECT DISTINCT
       user_id,
       verify_state,
       DATE(verify_date) the_date,
       MIN(verify_date) OVER (PARTITION BY user_id, DATE(verify_date)) min_datetime,
       LEAD(Verify_State,1) OVER (PARTITION BY user_id 
ORDER BY user_id, verify_date) as Nxt_row_State, 
       MAX(verify_date) OVER (PARTITION BY user_id, DATE(verify_date)) max_datetime
FROM tbl_excel_attendance) as q
where q.verify_state = 0 and q.nxt_row_state = 1
ORDER BY q.user_id, q.the_date;

Example for SQL Fiddle

Desired issue:

id  user_id      verify_date    verify_state  Nxt_row_State    TO_Date
6      16    2019-11-06 07:00:00    0            1       2019-11-06 19:45:00
3      16    2019-11-07 07:35:00    0            1       2019-11-07 18:05:00
13     19    2019-11-05 06:57:00    0            1       2019-11-05 18:28:00
10     19    2019-11-07 06:42:00    0            1       2019-11-07 18:04:00
20     40    2019-11-06 20:39:00    0            1       2019-11-07 06:39:00

html5 – How can I load a set of records into a data table without first loading them into Laravel?

I have a database with a single table that contains thousands of records. So I have a data table in the Blade view, which is a component of the admin template that I've integrated with Laravel. In the control I received the records in this way:

    $proyectos = DB::table('proyectos_inv')->paginate(50);
    return view('home',('proyectos' => $proyectos));

And I usually have it in the Blade view with an @foreach.
It turns out that the view data table loads the following script

  

What happens is that the pagination does not work as I imagined. The first 50 records are loaded as in this case, but not all are loaded. When I delete the function

page

The browser loads all the records and when it's done, it's this page. Can I just load the number of records I want in the beginning and not how it works?

This table is just a proof because the real table contains millions of records and in practice it is not effective to wait for the download of all records to automatically paginate.

Duplication – How do I remove these duplicate records in an Oracle 12c database?

I have these two tables:

messages(id primary key, message_date, created_at, ...)
user_messages(user_id, message_id references messages(id))

I have some duplicate lines in messages:

select user_id, message_date, count(*)
from messages inner join user_messages 
on messages.id = user_messages_message_id
group by user_id, message_date;

user_id | message_date | count(*)
1       | 2019-01-01   | 2
1       | 2019-02-01   | 3
1       | 2019-03-01   | 2

How can I remove such duplicates and keep only one, for example the one it is? created_at (Not message_date) is the minimum?

Differential Equations – Question: How can multiple records with repeated experiments be fit to a model?

I have a question, for example from Oleksandr R. in How do I fit 3 records to a model of 4 differential equations?

Oleksandr R. made some fake data from a given model, and the values ​​of kinetic coefficients k1, k2 and k3 were given as follows:

sol = ParametricNDSolveValue({a'(t) == -k1 a(t) b(t) + k2 x(t), 
    a(0) == 1, b'(t) == -k1 a(t) b(t) + k2 x(t) - k3 b(t) x(t), 
    b(0) == 1, x'(t) == k1 a(t) b(t) - k2 x(t) - k3 b(t) x(t), 
    x(0) == 0}, {a, b, x}, {t, 0, 10}, {k1, k2, k3});

abscissae = Range(0., 10., 0.1);
ordinates = 
  With({k1 = 0.85, k2 = 0.15, k3 = 0.50}, 
   Through(sol(k1, k2, k3)(abscissae), List));

data = ordinates + 
   RandomVariate(NormalDistribution(0, 0.1^2), Dimensions(ordinates));
ListLinePlot(data, DataRange -> {0, 10}, PlotRange -> All, 
 AxesOrigin -> {0, 0}, PlotStyle -> {Blue, Orange, Green})

Enter image description here

In the figure above, the curve of a is blue, orange is b, and green is x.

In the above article, Oleksandr R. has developed a way to adjust the three curves by adding an index of 1, 2 or 3 to the data set.

But what happens if you have multiple curves for the same substance, for example, if you perform several experiments with different initial concentrations? We can assume that the kinetic coefficients k1, k2, and k3 are constant and do not vary between experiments. This is a reasonable assumption, at least formally, especially when the concentrations are low. Is it then possible to adjust all data?

For example, let's create two sets of fake data from different initial conditions. Follow the above code:

sol1 = ParametricNDSolveValue({a'(t) == -k1 a(t) b(t) + k2 x(t), 
    a(0) == 1, b'(t) == -k1 a(t) b(t) + k2 x(t) - k3 b(t) x(t), 
    b(0) == 1, x'(t) == k1 a(t) b(t) - k2 x(t) - k3 b(t) x(t), 
    x(0) == 0}, {a, b, x}, {t, 0, 10}, {k1, k2, k3});
sol2 = ParametricNDSolveValue({a'(t) == -k1 a(t) b(t) + k2 x(t), 
    a(0) == 0.75, b'(t) == -k1 a(t) b(t) + k2 x(t) - k3 b(t) x(t), 
    b(0) == 0.4, x'(t) == k1 a(t) b(t) - k2 x(t) - k3 b(t) x(t), 
    x(0) == 0}, {a, b, x}, {t, 0, 10}, {k1, k2, k3});
abscissae = Range(0., 10., 0.1);
ordinates1 = 
  With({k1 = 0.85, k2 = 0.15, k3 = 0.50}, 
   Through(sol1(k1, k2, k3)(abscissae), List));
ordinates2 = 
  With({k1 = 0.85, k2 = 0.15, k3 = 0.50}, 
   Through(sol2(k1, k2, k3)(abscissae), List));

data1 = ordinates1 + 
   RandomVariate(NormalDistribution(0, 0.1^2), Dimensions(ordinates1));
data2 = ordinates2 + 
   RandomVariate(NormalDistribution(0, 0.1^2), Dimensions(ordinates2));
ListLinePlot(Join(data1, data2), DataRange -> {0, 10}, 
 PlotRange -> All, AxesOrigin -> {0, 0}, 
 PlotStyle -> {Blue, Orange, Green})

Enter image description here

How do you adjust the six curves (three functions from two different experiments) simultaneously? How should Oleksandr's code be modified to achieve this? Thanks!!

SQL Server 2005 – Select all records from 2 separate tables

ONE CROSS JOIN or CROSS APPLY gives a & # 39; cartesian product & # 39; or & # 39; cross product & # 39; back (that is, any combination of rows from the two tables). In this case, these operators are functionally equivalent.

-- set up our tables
CREATE TABLE Customer (
    CustomerNumber int
)

CREATE TABLE Product (
    Product varchar(15)
)

INSERT INTO Customer ( CustomerNumber )
VALUES 
    ( 1 )
    , ( 2 )
    , ( 3 )

INSERT INTO Product ( Product )
VALUES
    ( 'Item1' )
    , ( 'Item2' )
    , ( 'Item3' )

-- use a CROSS JOIN
SELECT
    CustomerNumber
    , Product
FROM
    Customer
CROSS JOIN
    Product

-- OR use a CROSS APPLY
SELECT
    CustomerNumber
    , Product
FROM
    Customer
CROSS APPLY
    Product

The difference between the JOIN and APPLY operators is that APPLY on the right can have a table-valued function that uses parameter values ​​from the column values ​​on the left-hand side. So the APPLY can do some nicer things.

All details can be found here:
https://docs.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql

MySQL 5.7.26 data exists in the .ibd file, but there are 0 records in the table

We found an old MySQL database that we want to restore. What does it mean if the .ibd file uniquely contains data when it is opened in Notepad ++ (the .ibd file is 288 KB in size), but the table does not contain any records? How can I restore the data?

I thought maybe I could copy and run the .ibd file into a tmp directory:

ALTER TABLE mytable DISCARD TABLESPACE;

… copy the .ibd file back to the data directory and start:

ALTER TABLE mytable IMPORT TABLESPACE;

However, the table still contained 0 records.

I thought then maybe I would have to lock the table and generate a .cfg file:

FLUSH TABLE mytable

… and then copying the .ibd and .cfg files to a tmp directory, but afterwards

UNLOCK;
ALTER TABLE mytable DISCARD TABLESPACE;

… copy the .ibd and .cfg files into a tmp directory and then

ALTER TABLE mytable IMPORT TABLSPACE;

The table still contained 0 records.

I even tried rebuilding the table from the definition extracted from the .frm file with mysqlfrm:

mysqlfrm d:tempmydbmytable.frm --diagnostic

and then discard / import the tablespace, but I have the error "LSNs in table can not be reset".

Based on the feedback from mysqlfrm, the mysql version of the .frm file is 5.7.26.

Any suggestions on how I can recover this data?