Thursday, January 5, 2017

How to get multiple Instagram users using curl in php



If you want to show Instagram user listing in your website using Instagram api.

<?php

       $accessToken = "enter your access token here";
$userid = array(0123456789,0123456789,0123456789,0123456789);

foreach($userid as $users):
    $url = "https://api.instagram.com/v1/users/".$users."?access_token=".$accessToken;
$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);
    $result = json_decode($result);
?>
  <div class="row-col-3">
  <a href="#">
  <div class="feature-shoutout-col">
  <div class="feature-image"><img src="<?php echo $result->data->profile_picture;?>" alt=""></div>
  <div class="feature-info">
  <p class="feature-title"><?php echo $result->data->counts->followed_by;?> followers</p>
  <p class="feature-username">@<?php echo $result->data->username;?></p>
  <p class="feature-price">$300</p>
  </div>
  </div>
  </a>
  </div>
 <?php endforeach;?> 

Monday, January 2, 2017

How to work with Instagram api



How to get Instagram user profile image, number of followers using ajax and jQuery.


<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script>
$(document).ready(function(){

$("#usersearch").keyup(function(){

     var userName = $("#usersearch").val();
    var token = '{enter your access token}',
     username = userName,
    num_photos = 4;

$.ajax({ // the first ajax request returns the ID of users
url: 'https://api.instagram.com/v1/users/search',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, q: username}, // actually it is just the search by username
success: function(data){
//alert(JSON.stringify(data));
//alert(JSON.parse(data));
//alert(data.data[0].username);
//alert(data.data[0].counts.followed_by);
//var profile_img = data.data[0].profile_picture;
/* $("#profile-pic").attr('src',profile_img);
$("#userId").text(data.data[0].id); */

$.ajax({
url: 'https://api.instagram.com/v1/users/' + data.data[0].id + '?access_token={enter you access token here}',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, count: num_photos},
success: function(data2){

var user_name = data2.data.username;
var followed_by = data2.data.counts.followed_by;
var prifile_pic = data2.data.profile_picture;

$("#username").text(user_name);
$("#profile-pic").attr('src',prifile_pic);
$("#followd").text(followed_by);

    },
error: function(data2){
console.log(data2);
}
});
},
error: function(data){
console.log(data);
}
      });
   });
 });
</script>
</head>
<body>
<input type="text" id="usersearch">
<span id="username"></span>
<span id="userId"></span><br>
<span id="followd"></span><span>Followers</span>
<img src="" id="profile-pic">
</body>
</html>

Wednesday, December 21, 2016

How to change one selected option text to another select option text using jQuery

How to change one selected option text to another select option text using jQuery.

Firstly you need to get option text which you want to put on second selection select option text.


<script>
$(document).ready(function(){

   $("input.manual").on("click",function(){

   var dob_day = $("li.pms-field.register-dob select.day option:selected" ).text();
 var dob_month = $("li.pms-field.register-dob select.month option:selected" ).text();
 var dob_year = $("li.pms-field.register-dob select.year option:selected" ).text();

 $("li.pms-field.popup-dob select.day option:selected" ).text(dob_day);
 $("li.pms-field.popup-dob select.month option:selected" ).text(dob_month);
 $("li.pms-field.popup-dob select.year option:selected" ).text(dob_year);


        });
});
</script>


Tuesday, December 20, 2016

What is the default time of session in php

Php default session time  24 minutes (1440 seconds). Its depends on server configuration.

You can change it in your php-configuration on your webserver. you just need to find on php.ini file session.gc_maxlifetime=1440 you can change the php session default time.



How to show category and subcategory in core php

Learn how to show category and subcategory in core php with mysql.

Firstly you need to crate tow table one for category and second for subcategory.







<?php

mysql_connect('localhost','root','password')or die('could not connect');
mysql_select_db('category_subcategory')or die('could not select db');

$sql="select * from category";
$query = mysql_query($sql);
echo"<ul>";
while($row = mysql_fetch_assoc($query))
{

$id =$row['id'];
echo"<li>".$row['category'];
$sql1="select * from subcategory where category_id='$id'";
$query1 = mysql_query($sql1);
echo"<ul>";
while($row1 = mysql_fetch_assoc($query1))
{
 echo '<li>'.$row1['subcategory'].'</li>';
}
echo'</ul>';
echo '</li>';
}
echo'</ul>';

?>

Your output would be like this