i am migrating Database in which i migration first 1000 rows but problem is that i need all the data after id = 1000 i am not getting the exact result. Please see my query
Tried 1
$count = oldo::count();
$skip = 1000;
$limit = $count - $skip; // the limit
$oldOrder = oldo::skip($skip)->take($limit)->orderby('Std_ID')->paginate(500);
Tried 2
$oldOrder = oldo::skip(1000)->orderby('Std_ID')->paginate(500);
PS:
Some rows are delete i need data via Primary key
You probably want to do the following:
<?php
$oldOrder = oldo::where('Std_ID', '>', 1000)->paginate(500);
This way you select all orders where the ID is more than 1000
Related
I have 2 mysql tables with 500.000 items
first with items price, items id, and ticket number
second with ticket_number, date of sales and total_price of ticket
by now i use this query
SELECT items.pri,ticket.date,items.crd,items.plu
FROM items ,ticket
WHERE
(items.crd = 25 OR items.crd = 30) AND items.SeqNbr = ticket.SeqNbr
then in php:
$val_1 = array();
$price1 = 0;
while($row = mysql_fetch_array($query))
{
if($row['crd'] == 25)
{
$prix = $row['pri'];
if($prix != $price1)
{
$val_1[] = array( (int)$row['date']*1000,(float)$row['pri']);
$price1 = $prix;
}
}
}
return:
[[1388552879000,1.519],[1389136505000,1.498],[1392420222000,1.514],[1394667334000,1.499],[1395373887000,1.478],[1395963467000,1.499],[1396649284000,1.52],[1397513210000,1.542],[1398384245000,1.556],[1399347974000,1.536],[1400910286000,1.553],[1403216692000,1.58],[1405029076000,1.563]]
goal is obtain an array with price change and date to build a charts of price fluctuation.
but with more than 500.000 records this is extremly slow (15 sec)
is there any possibilities to build mysql query that return the same array ?
Thanks
First you need to check where is the bottleneck, on the query or on the loop.
If it is on the query, check if you have the right index. If not, try adding index for the fields items.crd, items.SeqNbr and ticket.SeqNbr.
How can I execute insert queries while retrieving data from database?
I mean that after running a select query where I am retrieving data using a while loop, I also want to insert some fields into another table.
I want to execute inserts forcefully in PHP code.
I tried:
$firstview=mysql_query("insert into kadam_firstview(jobtype,jobname,admin_id,date,datetime)values('".$trial."','".$jobname."','".$adminid."','".$time."','".$date."')");
$firstview.execute();
But it doesn't work.
i want to run upper query inside select query as i am getting data from select query at that same time i want to save those data inside another table but query giving error which is mentioned above
I think your question is more for php developer then for dba.
Anyway if I understand you correctly you would like to select a record set from a table and insert this values (or modified one) into another table?
<?php
$db = new mysqli("host", "username", "password", "databasename");
$result = $db->query("SELECT * FROM table_name");
while ($row = $result->fetch_object()) {
$trail = $row->trail;
$jobname = $row->jobname;
$adminid = 25;
$time = $row->time;
$date = $row->date;
$query = "insert into kadam_firstview(jobtype,jobname,admin_id,date,datetime) values('".$db->escape_string($trial)."','".$db->escape_string($jobname)."','".$db->escape_string($adminid)."','".$db->escape_string($time)."','".$db->escape_string($date)."')";
$db->query($query);
}
this will copy the rows from the table "table_name" into the table "kadam_firstview" and set the adminid to 25.
http://php.itronic.at/manual/en/class.mysqli.php
I have a database similar to this:
table name = jos_school ... id = Primary key, name = Unique key
id name no_of_students no_of_staffs fees
1 schoolA 0 0 0
2 schoolB 0 0 0
...
...
In phpMyAdmin I did something like this, and it worked (successfully updated multiple rows and columns),
UPDATE jos_school
SET no_of_students = CASE name
WHEN 'schoolA' THEN '1523'
WHEN 'schoolB' THEN '546'
....
END,
no_of_staffs = CASE name
WHEN 'schoolA' THEN '1234'
WHEN 'schoolB' THEN '346'
....
END
WHERE name IN ('schoolA', 'schoolB')
However, I was not able to update the table USING JOOMLA's Update methods. I don't want to use foreach and update the table over 1000 times. I want to execute a single query.
I've also read: http://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase#Updating_a_Record
and dint found it helpful in this case.
So, can someone point me to the right direction.
You can query as below,
// Create a new query object.
$db = &JFactory::getDBO();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query="UPDATE jos_school SET no_of_students = CASE name";
foreach($data as $d)
{
$query.=".....";
}
$query.=".....";
$db->setQuery((string)$query);
Hope that helps ...
I have a query that is running
$this->db->select('Parent_Username, Program_Subtype, Is_Chaperone,Participant_name,Role,Percent_completed,Wizard_ID');
$this->db->where('Parent_Username', $username);
$this->db->where('Program_ID', $Program_ID);
$query = $this->db->get($this->child_table);
an echo produces:
SELECT `Parent_Username`, `Program_Subtype`, `Is_Chaperone`, `Participant_name`,
`Role`, `Percent_completed`, `Wizard_ID` FROM (`child_table`)
WHERE `Parent_Username` = 'test123' AND `Program_ID` = 'abcdef3423' LIMIT 1
So where is that Limit 1 coming from, when I don't specify it, I need all records, I can set an arbitrary limit like $this->db->limit('502340234234235'); but why should I have to, why is it limiting it to 1 record when I don't specify it to?
I had the following code:
select DB.T1.ID,
DB.T1.B,
DB.T1.C,
DB.T2.ID,
DB.T2.B,
DB.T2.R,
DB.T3.ID,
DB.T3.Q
DB.T1.DUP,
DB.T2.DUP,
DB.T3.DUP
from DB.T1, DB.T2, DB.T3
where DB.T1.id = DB.T2.ID
and DB.T1.id = DB.T3.ID
and DB.T2.id = DB.T3.id
and DB.T1.DUP = 'not_duplicate'
and DB.T2.DUP = 'not_duplicate'
and DB.T3.DUP = 'not_duplicate'
;
The output returned 0 rows, however. So, I changed the values of the "DUP" column in each table from duplicate/not_duplicate instead to 0/1. I tried this code and it worked:
select DB.T1.ID,
DB.T1.B,
DB.T1.C,
DB.T2.ID,
DB.T2.B,
DB.T2.R,
DB.T3.ID,
DB.T3.Q
DB.T1.DUP,
DB.T2.DUP,
DB.T3.DUP
from DB.T1, DB.T2, DB.T3
where DB.T1.id = DB.T2.ID
and DB.T1.id = DB.T3.ID
and DB.T2.id = DB.T3.id
and DB.T1.DUP = 1
and DB.T2.DUP = 1
and DB.T3.DUP = 1
;
The second code works perfectly, the first one returned 0 rows. Does anyone know why was this happening? The values "not_duplicate" and "duplicate" were the exact same strings as the csv's that I imported into the database from. I can't explain why this would be the case and I'm really pretty curious.
Thanks very much!
because the DUP column they dont have this not_duplicate in fields. they have 1
then it doesnt match your query .
the query returns values which are stored in the column DUP .