Control Statements in Python

We know that loops are used to execute a set of statements repeatedly sometimes we need to control execution of the program based on the values and the conditions, so to accomplish this task Control Statements are using in python ,python support three types of Control Statements Continue Statement,Break Statement and the Pass Statement. Lets see in details one by one

Continue Control Statement in Python

Sometimes we need to exclude particular iteration inside the loop in that case “Continue” Control Statements is used to accomplish control to the beginning of the loop.if the condition is true it will return to the beginning of the loop.

Example


# Continue Control Statement in Python

#for loop to print a number between 1 to 4 without 2

l = [1, 2, 3, 4] 
for i in l: 
    if i==2:
       continue
    print(i) 



Out put
1
3
4

Break Control Statement in Python

Sometimes we need to stop the iteration based on particular logic or condition Break Statement is used to accomplish this task .Break statement break stop the execution of the loops

Example

# Break Control Statement in Python


l = range(1, 100)
for i in l: 
    if i==10:
       break   #stop the execution here if i equal to 10
    print(i) 

Output

1
2
3
4
5
6
7
8
9

Pass Control Statement in Python

If we want to execute nothing pass statement can be used. Sometimes we need to implement functionality code after beta delivery of the project we use “pass” to keep a loop without anything


l = [1, 2, 3, 4] 
for i in l :  
    pass

How to convert xml format data in to an array using php

How to convert xml format data in to an array using php

Most of the common web service API return the result in XMl Format to change the data as per the our UI, we need to convert it into array , Let See how to convert xml format data in to an array using php

Here we have API to get product data and the result is in XML format, so in the tutorial we have to convert xml format data in to an array using php

$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
$url2="http://productsearch.linksynergy.com/productsearch?token=8dcb9db02dce5b1123f84d8950beb34de9bfb0169dc6fca4146a059926f0239b&MaxResults=60&pagenumber=1&keyword=".$_GET['v']."&sort=retailprice&sorttype=asc&sort=productname&sorttype=asc";
curl_setopt($ch, CURLOPT_URL, $url2);
$xml_data = curl_exec($ch);

See result in in XML format

See how to convert xml format to array in php

#xml format data in to an array using php
curl_close($ch);

print_r($xml_data);

#See the out put in XMl Format

$object = simplexml_load_string($xml_data);

#you can use simplexml_load_string to convert to convert xml format to array in php

foreach($object->item as $signprod)
{
print_r($signprod);	  //Display All values in array
}

#xml format data in to an array using php
See how to convert xml format to array in php 2

Linkshare product serach api code

Here is the simple code to fetch product from all the affiliate using Linkshare , Linkshare product serach api code

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
$url2="http://productsearch.linksynergy.com/productsearch?token=8dcb9db02dce5b1123f84d8950beb34de9bfb0169dc6fca4146a059926f0239b&MaxResults=60&pagenumber=1&keyword=".$_GET['v']."&sort=retailprice&sorttype=asc&sort=productname&sorttype=asc";
curl_setopt($ch, CURLOPT_URL, $url2);
$xml_data = curl_exec($ch);
curl_close($ch);
$object = simplexml_load_string($xml_data);
foreach($object->item as $signprod)
{
print_r($signprod); 
}

Select all data from MySQL where date between two given dates

Here is the simple MySQL query to fetch data between given date range

See MySQL query



$f_date=$_REQUEST['f_date'];

$t_date=$_REQUEST['t_date'];

"SELECT * FROM sales WHERE  sales_invoice_date between '".date('Y-m-d',strtotime($f_date))."' and '".date('Y-m-d',strtotime($t_date))."' "

To Fetch all the sales data in the given date

"SELECT * FROM sales WHERE sales_invoice_date='".date('Y-m-d',strtotime($f_date))."'" 

To fetch Today’s Sales

SELECT * FROM sales WHERE STR_TO_DATE(sales_invoice_date , '%d-%m-%Y') = CURDATE()