Import a CSV File Using PHP and MySQL

 <?//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,”r”);

//loop through the csv file and insert into database
do {

if ($data[0]) {
mysql_query(“INSERT INTO contacts_tmp (contact_first, contact_last, contact_email) VALUES
(
‘”.addslashes($data[0]).”‘,
‘”.addslashes($data[1]).”‘,
‘”.addslashes($data[2]).”‘
)
“);
}

} while ($data = fgetcsv($handle,1000,”,”,”‘”));

?>

Choose your file:

Advertisements

Export MySql Data to a csv file using php

<?
$filename = $sitename . ‘my csv.’ . date( ‘Y-m-d-H-i-s’ ) . ‘.csv’;

header( ‘Content-Description: File Transfer’ );
header( ‘Content-Disposition: attachment; filename=’ . $filename );
$fields=”ID”.”,”.”Property_Title”.”,”.”Description”.”,”.”property_type”.”,”.”location”.”n”;
$data=””;
$querypl= “SELECT * FROM mytable”;
$resultsrows = mysql_query($querypl);
while($rowpl = mysql_fetch_array($resultsrows))
{
$ID=$rowpl[‘ID’];
$property_title=$rowpl[‘property_title’];
$property_desc=$rowpl[‘property_desc’];
$property_type=$rowpl[‘property_type’];
$location=$rowpl[‘location’];

$data .= $ID”.”,”.$property_title.”,”.$property_desc.”,”.$property_type.”,”.$location.”n”;
}

echo $fields.$data;
exit;

?>

How To Fetch Instagram Images Using HashTag

<php

$hashtag='Test_hastTag';

$result1 = fetchData("https://api.instagram.com/v1/tags/{$hashtag}/media/recent/?access_token={$accessToken}");
$result1 = json_decode($result1);
?>
<?php foreach ($result1->data as $post): ?>
<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
<?php endforeach ?>

<?php

function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}

?>
You can use Instpic plugin in wordpress