What is the max length of result of http://ip-api.com/docs/api:serialized_php ?
[region] => XX
[timezone] => Europe/Paris
[org] => Free SAS
[query] => 78.221.XXX.XXX
[regionName] => Upper Garonne
[zip] => 31320
[lat] => XX.111111111111
[lon] => YY.1111111111111
[as] => ZZ11111 PROXAD
[status] => success
[country] => NNNNNN
[countryCode] => UU
[city] => AAAAAAAAAAAAAAAAA
[isp] => DDDD DD
To avoid requesting this api multiple times for the same IP address, I would like to store the result in a MySQL database. But I don't know how long can be the results.
I mean, it's specific to the ip-api.com. If I specify a column of varchar 100 for regionName. Can a regionName have more than 100 characters?
Related
I have been using PHP Client library for Exact Online for a long time.
After saving the customer Accounts, Addresses, Contacts and then filtering out the PaymentConditions based on WooCommerce orders, items are successfully reflecting in the Exact Online dashboard.
But unfortunately calling the SalesOrders post request API. I'm unable to store into the Exact Online dashboard,
even though in order to store only OrderedBy itself is enough which is given in the official documentation
$ordersn = $order->save();
Picqer\Financials\Exact\ApiException : Error 403: Forbidden
$order = new SalesOrder($connection);
$lines = new SalesOrderLine($connection);
....
echo'<pre>'; print_r($order);
$order->SalesOrderLines = $lines;
$ordersn = $order->save();
if ($ordersn->ID)
{
$orderitem['sync_flag'] = true;
}
Here is the details of an order array
Picqer\Financials\Exact\SalesOrder Object
(
...
[attributes:protected] => Array
(
[WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
[OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
[OrderedBy] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
[DeliverTo] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
[OrderDate] => 2019-02-17T19:29:53
[YourRef] => 75591901YP220320G
[OrderedByName] => Peter Kerner
[Description] => 16031_PayPal/Lastschrift/Kreditkarte
[Remarks] => Order is processing
[PaymentReference] => 16031
[PaymentCondition] =>
[SalesOrderLines] => Picqer\Financials\Exact\SalesOrderLine Object
(
[attributes:protected] => Array
(
[OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
[VATAmount] => 5,58
[Description] => Goodies Box
[Quantity] => 1,00
[UnitPrice] => 29,37
[Item] => 418d43d6-55fe-410a-8df2-b05cbb72cea5
)
...
)
)
...
)
Do we need to upload VAT code or Am I missing something else data to be resided first shown from the above order-array or what else should we need to call appropriate API. Since in-order to reflect on the Exact Online dashboard. what should we need to follow?
From the built-In function call addItem() below snippets of code:
$soLines = array(
'OrderID' => $lines->OrderID,
'Item' => $lines->Item,
'Description' => $lines->Description,
'Quantity' => $lines->Quantity,
'UnitPrice' => $lines->UnitPrice,
'VATAmount' => $lines->VATAmount,
'VATCode' => $lines->VATCode
);
$order->addItem($soLines);
Generates the results with LineNumber to be included in SalesOrderLines array
[attributes:protected] => Array
(
[WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
[DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
[OrderDate] => 2019-02-17T20:45:34
[YourRef] => 9Y9593859V795183K
[OrderedByName] => Katrin Lenk
[Description] => 16033_PayPal Express
[Remarks] => Order is processing
[PaymentReference] => 16033
[PaymentCondition] =>
[SalesOrderLines] => Array
(
[0] => Array
(
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
[Description] => ABC Classic
[Quantity] => 2,00
[UnitPrice] => 15,08
[VATAmount] => 5,73
[VATCode] =>
[LineNumber] => 1
)
)
)
Also note I haven't created Journals, GLAccounts, Documents & DocumentAttachments API. Does this actually affects storing of SalesOrders
EDIT:
In much simpler
$salesOrder = new \Picqer\Financials\Exact\SalesOrder($connection);
$salesOrder->WarehouseID = '26ca2016-453f-499a-8a34-c986009bc78d';
$salesOrder->OrderID = '65F93F56-97A8-4D54-AE37-C0BDDE774E67';
$salesOrder->OrderedBy = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->DeliverTo = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->OrderDate = '2019-02-17T20:45:34';
$salesOrder->YourRef = '9Y9593859V795183K';
$salesOrder->OrderedByName = 'Katrin Lenk';
$salesOrder->Description = '16033_PayPal Express';
$salesOrder->Remarks = 'Order is processing';
$salesOrder->PaymentReference = '16033';
$salesOrder->PaymentCondition = 'PP';
$soLines = array(
'Item' => '5c415369-615c-4953-b28c-c7688f61cfaa',
'Description' => 'ABC Classic',
'Quantity' => '1,00',
'UnitPrice' => '29,37',
'OrderID' => '65F93F56-97A8-4D54-AE37-C0BDDE774E67'
);
echo '<pre>'; print_r($soLines);
$salesOrder->addItem($soLines);
echo '<pre>'; print_r($salesOrder);
$salesOrder->save();
Resulting value stored from the soLines array
[attributes:protected] => Array
(
[WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
[DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
[OrderDate] => 2019-02-17T20:45:34
[YourRef] => 9Y9593859V795183K
[OrderedByName] => Katrin Lenk
[Description] => 16033_PayPal Express
[Remarks] => Order is processing
[PaymentReference] => 16033
[PaymentCondition] =>
[SalesOrderLines] => Array
(
[0] => Array
(
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
[Description] => ABC Classic
[Quantity] => 2,00
[UnitPrice] => 15,08
[VATAmount] => 5,73
[VATCode] =>
[LineNumber] => 1
)
)
)
Actual Result:
Picqer\Financials\Exact\ApiException : Error 403: Forbidden
The reason was OrderID value was included twice in the SalesOrderLine as well as in SalesOrder for the two REST API calls and removing the OrderID entry from SalesOrder worked perfectly and reflecting in the Exact Online Dashboard
You cannot assign $order->SalesOrderLines = $lines; directly resulting in a collection to array error.
The only way to do this was to call via in-built function called addItem() passing array objects into it.
I have three tables:
Student - UPN, Name, Year, House
Seclusion_Status - ID, Arrived, FTE, Rebuild, DateTimeAdded, Staff, Student_UPN (fk), Comment
Period_Rating - ID, Slot_ID, Rating, Date, Seclusion_ID (fk)
Each student can have many entries in the Seclusion_Status table, and then there are also many entries in the Period_rating table, which is linked to the Seclusion_status table with the Seclusion_ID
I am running the following query to return a record from Seclusion_Status based on a date, and then all the records in the Period_rating table that relate to the Seclusion_status record.
$sql="SELECT * FROM Seclusion_Status
INNER JOIN Students ON Seclusion_Status.Student_UPN=Students.UPN
JOIN Period_Rating ON Seclusion_Status.ID=period_rating.Seclusion_ID
WHERE period_rating.Date = '$start'
GROUP BY period_rating.Seclusion_ID
ORDER BY Seclusion_Status.DateTimeAdded ASC";
$result=mysql_query($sql);
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
The query is returning the Seclusion_Status record, and then the first record in Period_rating, but not the others.
Array
[0] => 348
[ID] => 157
[1] => Y
[Arrived] => Y
[2] => N
[FTE] => N
[3] =>
[Rebuild] =>
[4] =>
[Text] =>
[5] => 2016-03-04 09:30:50
[DateTimeAdded] => 2016-03-04 09:30:50
[6] => Mr S Holland
[Staff] => Mr S Holland
[7] => K80222800
[Student_UPN] => K8022280
[8] => Refusing instructions
[Incident] => Refusing instructions
[9] =>
[Period] =>
[10] =>
[Period_In_ID] =>
[11] => Not sitting properly in class despite being asked
[Comment] => Not sitting properly in class despite being asked
[12] => K80222800
[UPN] => K80222800
[13] => Student Name
[Name] => Student Name
[14] => Year 9
[Year] => Year 9
[15] => Acer
[House] => Acer
[16] => 157
[17] => P2
[Slot_ID] => P2
[18] =>
[Rating] =>
[19] => 2016-03-04
[Date] => 2016-03-04
[20] => 348
[Seclusion_ID] => 348
[21] => 1
[Status] => 1
The query is returning the Seclusion_Status record, and then the first record in Period_rating, but not the others.
You have a GROUP BY period_rating.Seclusion_ID that instructs mysql to return one record per Seclusion_ID. Take the group by clause out, and the query will return multiple records, that match.
The thing is if you use join, if data is there in all the three tables then only it will fetch.
If you want to fetch all the entries in the table you need to use outer join, unfortunately u cant use outer join in mysql.
but you can fetch results by unioning leftjoin results and right join results
I have two tables:
1)
CREATE TABLE IF NOT EXISTS book(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
class__id INT,
book_order INT,
title VARCHAR(255),
content TEXT(65535)
) ENGINE=MyISAM;
2)
CREATE TABLE IF NOT EXISTS book_image(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
class__id INT,
type VARCHAR(12),
type__id INT,
image_order INT,
url VARCHAR(50)
) ENGINE=MyISAM;
I need to get a list of books for a given book.class__id, and all images for each of those books with book_image.type = 'book' and book_image.type__id = book.id. Furthermore, the book_images need to be ordered by the image_order column, separately for each book.
I need the resulting object to look somewhat like this:
object(stdClass)
'books' => array (size=2)
0 =>
object(stdClass)
'id' => 13
'class__id' => 55
'book_order' => 1
'title' => xyz
'content' => xyz
'book_images' => array (size=2)
0 =>
object(stdClass)
'id' => 529
'class__id' => 55
'type' => book
'type__id' => 13
'image_order' => 1
'url' => xyz
1 =>
object(stdClass)
'id' => 27
'class__id' => 55
'type' => book
'type__id' => 13
'image_order' => 2
'url' => xyz
1 =>
object(stdClass)
'id' => 21
'class__id' => 55
'book_order' => 2
'title' => xyz
'content' => xyz
'book_images' => array (size=1)
0 =>
object(stdClass)
'id' => 420
'class__id' => 55
'type' => book
'type__id' => 21
'image_order' => 1
'url' => xyz
I'd like to avoid a convoluted foreach() loop with mutliple queries one after the other for each book... I tried various types of joins and select subqueries to no avail.
How do I do this with a single query?
I am exporting data from mysql to excel in codeigniter it's working fine on localhost
but it's not working on server .on server it prints only array like this.
Array
(
[0] => Array
(
[id] => 135
[type] => 3
[product_service] =>
[email] => bewcontrols#gmail.com
[first_name] => gurwinder sigh
[last_name] =>
[company_name] =>
[country] =>
[state] =>
[city] =>
[phone_number] => 91-011-09971587701
[mobile] => 09971587701
[fax_number] =>
[address] => f-127 mayapuri indl area phase2 new delhi
[zipcode] =>
[message] => Subject: Fwd to purchase/ maint. for repairing of SOLENOID VALVE and PNEUMATIC cylinders ,DELHI,BHUPINDER ENGG.
Dear Sir,
I'd like to take this opportunity to introduce BEW Pneumatic
Controls,Delhi, to you.
We manufacture Heavy Duty Solenoid Valves in Spool construction
using all-Aluminium fittings.While most manufacturers use plastic
fittings,plastic cages, we at BEW pioneered Aluminium fittings and
have incorporated them across our product line.
Please find attached our latest product catalogue for your perusal and
we look forward to hearing from you soon.
Best Regards,
Gurwinder Singh
Mobile-09811019362,
and 09971587701
[status] => 1
[reply_status] => N
[receive_date] => 2014-11-16 18:22:06
[order_quantity] =>
)
[1] => Array
(
[id] => 134
[type] => 3
[product_service] =>
[email] => mohamed#gmail.com
[first_name] => mohamed
[last_name] =>
[company_name] =>
[country] =>
[state] => 0
[city] =>
[phone_number] =>
[mobile] => 9944556611
[fax_number] =>
[address] =>
[zipcode] =>
[message] => jhkhjh
[status] => 1
[reply_status] => N
[receive_date] => 2014-11-11 15:42:47
[order_quantity] => 20
)
<?php
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=filename.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
//fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
// fetch the data
mysql_connect('localhost', 'user', 'pass');
mysql_select_db("database");
$rows = mysql_query('SELECT something, something, something FROM table');
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
?>
ok its simple in CI
Just download csv library
then
$this->db->select('*')->from('yourtabl')->where(array('your_conditions'));
$query = $this->db->get();
$this->load->helper('csv');
query_to_csv($query, TRUE, 'yourfilename.csv');
and bingo
The MySQL query I'm currently trying to perform is functionally equivalent to this:
SELECT small_table.A, small_table.B, small_table.C, huge_table.X, huge_table.Y
FROM small_table LEFT JOIN huge_table
ON small_table.D = huge_table.Z
WHERE small_table.E = 'blah'
except that the query doesn't appear to terminate (at least not within a reasonable amount of time), probably because the second table is huge (i.e. 7500 rows with a total size of 3 MB). Can I perform a functionally equivalent join in a reasonable amount of time, or do I need to introduce redundancy by adding columns from the huge table into the small table. (I'm a total beginner to SQL.)
The clause WHERE small_table.E = 'blah' is static and 'blah' never changes.
Here is the EXPLAIN output as requested:
Array ( [0] => Array ( [0] => 1 [id] => 1 [1] => SIMPLE [select_type] => SIMPLE [2] => small_table [table] => small_table [3] => ref [type] => ref [4] => E [possible_keys] => E [5] => E [key] => E [6] => 1 [key_len] => 1 [7] => const [ref] => const [8] => 1064 [rows] => 1064 [9] => Using where [Extra] => Using where ) [1] => Array ( [0] => 1 [id] => 1 [1] => SIMPLE [select_type] => SIMPLE [2] => huge_table [table] => huge_table [3] => eq_ref [type] => eq_ref [4] => PRIMARY [possible_keys] => PRIMARY [5] => PRIMARY [key] => PRIMARY [6] => 4 [key_len] => 4 [7] => my_database.small_table.D [ref] => my_database.small_table.D [8] => 1 [rows] => 1 [9] => [Extra] => ) )
A few things ...
1) Are you executing this query directly in MySQL (either Workbench GUI or command line), or is this query embedded in PHP code? Your EXPLAIN output seems to suggest PHP. If you haven't done so already, try executing the query directly in MySQL and take PHP out of the mix.
2) Your EXPLAIN output looks Ok, except I'm wondering about your WHERE clause with small_table.E = 'blah'. The EXPLAIN output shows that there's an index on column E but the key length = 1, which is not consistent to the comparison with 'blah'. What data type did you use for the column definition for small_table.E?
3) MySQL is estimating that it needs to scan 1064 rows in small_table. How many total rows are in small_table, and how many do you expect should match this particular query?