OK, I have a simple xml call which retrieves data via an api, please see code below:
$file = 'http://mywebsite.com/computers.xml?apikey=88888&cid=api&limit=5&page=1 ' ;
if(!$xml = simplexml_load_file($file))
exit('Failed to open '.$file);
$total_pages = $xml->results->attributes()->totalPages;
$current_page = $xml->results->attributes()->currentPage;
$total_results = $xml->results->attributes()->totalResults;
foreach($xml->computer as $computer){
echo $computer['name'];
this all works perfect and breaks down the total number of pages, results and current page. With an if else statement i can generate next and previous buttons, however if i include the link to the api, when i click on it it simply calls the page and show the results as an xml format.
When what i want to achieve is yo provide a button which simply calls the second page of these results, i.e
$file = 'http://mywebsite.com/computers.xml?apikey=88888&cid=api&limit=5&page=2
however just clicking on this link shows the page in xml format, so what i need to do is to click on a button and retrieve the info via the simple xml function, however i do not know if this is possible or how to go about it.
And so any advice would be appreciated.
Thanks
You need to render a button that links to it's own url, plus a query parameter.
// get the param
$pageNum = $_GET['page'];
// modify your api call query string
$file = '...8888&cid=api&limit=5&page=' . $pageNum;
then your next button would link to
...href='ownpage.php?page=' . &pageNum + 1
and prev
...href='ownpage.php?page=' . &pageNum - 1
and I suppose your default page in the case where the page parameter is not supplied, you would default $pageNum to 1.
Related
$page = isset($input['page'])?$input['page']:0;
$perPageRecord = 10;
$calls = $this->twilio->calls->page(["to" => "+919876543210"],$perPageRecord,'',$page);
$data = [];
echo $calls->getNextPageUrl;
exit;
I am using above code to get next page url and it print successfully. But i want to print last page url while In php twilio.
Anyone can tell me how can i get last page url using twilio php.
Thanks
It looks like you will need to programmatically extract a returned range and manipulate the resulting data to get the X most recent results (last page).
Replacing Absolute Paging and Related Properties
Usage and Migration Guide for Twilio's PHP Helper Library 5.x
I am getting events from a page and noticed some were missing, this is because they are not in the first result but on another "page" (in the graph api explorer tool I can click 'next' at the bottom of my result.
How can I loop through everything there is?
Do I first need to create a loop for how many pages there are, and then create 1 big object/array containing all data?
Currently I have the following:
$json_object = file_get_contents("https://graph.facebook.com/v2.10/mypageid/events?fields=owner,start_time,cover,description,name,place&access_token=mytoken");
$feedarray = json_decode($json_object);
$f = 0;
$facebookfeed = '';
//Reversing to show newest events first
$facebookevents = array_reverse($feedarray->data);
foreach ($facebookevents as $key => $feed_data)
{
loop here
}
I tried to find out what changes when clicking on another page, but the only parameters that are added are: pretty=0 and limit=25 but this is the same on every page I click. Changing the limit does not work if I increase it.
How can I get ALL my data in one object/array?
I am trying to create a webpage to show some images returned by Flickr API. But there are thousands of images returned, so I can't put them on the same web page because then people need to scroll all the time. So I would like to put them into separate pages like we usually have, for example, "Page 1 2 3 next". But I don't know how to implement this. What I thought was using javascript to tell which page user chooses and then send this number to the API request. However, the API is handled by php and I don't know how to send a value from JS to PHP, so I haven't solved this problem yet. Could anybody give any thoughts! Thank you!
April
Here is the final solution for this problem:
php code for Flickr API call:
$page = 1;
$tag1 = "puppy";
$tag2 = "cute";
$flickrUrl = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=blablablabla&tag_mode=all&tags=$tag1\',\'$tag2&per_page=20&page=$page";
The solution is instead of assigning the $page to a specific number, use the following statement:
$page = isset($_GET['page']) ? $_GET['page'] : 1;
By doing this, the php file will get the page retrieved via Flickr API directly.
And then I use some DOM elements for example as the links for "Next Page" and "Previous Page" to help you navigate through different pages.
echo "<p id=\"nav_bar\">";
$back_page = $page - 1;
$next_page = $page + 1;
echo "<a href='?page=1'>First Page</a>";
if($page > 1) {
echo "<a href='?page=$back_page'>« <strong>Prev</strong></a>";
}
// if current page is not last page
if($page != $page_count) {
echo "<a href='?page=$next_page'><strong>Next</strong> »</a>";
}
$last_page = $page_count;
echo "<a href='?page=$last_page'>Last Page</a>";
echo "</p>";
Finally, thank you for everyone who has helped.
I am unfamiliar with the flickr api so I don't know exactly how you would want to paginate things, but just looking at what you posted you could use ajax to request the API call. So in your h4 do something like:
<h4 id=\"num_imgs\">
Page <span data-page="1">1</span> |
<span data-page="2">2</span> |
<span data-page="3">3</span> |
<span data-page="4">4</span> |
<span data-page="5">5</span>
</h4>
Then do a jqueryish call like:
$('h4 span').click(function(){
getImages($(this).data('page'));
}
Then have a javascript image handler function that fetches the images and processes them/displays them to the user.
getImages(page){
var flickrUrl = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=blablablabla&tag_mode=all&tags=$tag1\',\'$tag2&per_page=20&page="+page;
$.get(flickrUrl,function(data){
//PROCESS IMAGES
});
}
I hope that sort of setup makes sense. It seems to be what you are trying to do. You could make your page dynamic and still pass in the tags as well. Then you really don't need PHP to set up your page, but depending on how your user is selecting the tags, you may still do it via PHP. I would probably do the while thing via javascript.
I am implementing an online book application. It is based on html.
Generally, the book is double page . However , only single page is shown for the first page and it is page 1. I need loading six page for each time. For instance, if user read the 4th 5th page , what I need to get are 2th 3th 4th 5th 6th 7th pages.
So my idea is provide the folder name and one page number (i , e.g. i =
5th) and return i-3,i-2,i-1 ,i , i+1, i+2 image paths.
Here is some sample code I find:
public function getImage(){
$params = $this->getRequest()->getParams();
//d($params);
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$src = $params['image_path'];
exit;
}
}
It is useful? and How can I convert it to accept the folder name/ page number? Thank you
I have a custom report called my-newsletters in Google analytics. I want to fetch this report with a php call to $ga->requestReportData(...) and then parse the response and format it up.
First I made an account to collect all my newsletter open and click hits - each time someone opens a newsletter or clicks on a link in the newsletter I capture that with a call to the __utm.gif on Google. That part is working and I include in the call ( in the Landing Page aka utmp parameter) some data such as the word 'open' and 'click' to distinguish the events and also some other data i hope to parse out later, plus i use the campaign field and maybe I should do something with the source field too - now I just dup the utmp field. So far that part seems to work.
Now I need help to define a report that will return that utmp and campaign field info and the number of hits each has taken, sorted by date of hit I guess. then i need to call that report from my php and then later parse it - the parsing part I'm not worried about yet.
PS: here is the code I use to generate the utm url
function getGoogleUtmUrl($source='Emails', $referer='opens', $estid='0',$mailid='0', $campaign){
$stat_id='MO-xxx31982-1';
$var_utmcs=urlencode( 'UTF-8');
$var_utmac = $stat_id;
$var_utmhn = 'mysite.com'; //enter your domain
$var_utmn = rand(1000000000,9999999999); //random request number
$var_cookie = rand(10000000,99999999); //random cookie number
$var_random = rand(1000000000,2147483647); //number under 2147483647
$var_today = time(); //today
$var_referer = $referer; //referer url
$utm_source = 'my_newsletter';
$utm_medium = 'Emails';
$utm_campaign = $campaign;//$_GET['url'];
$var_uservar = $estid.'_'.$mailid; //enter your own user defined variable
$var_utmp = 'mysite.com/newsletters/'.$referer.'/'.$estid.'/'.$mailid;//.$estid;//$_GET['url']; //this example adds a fake file request to the (fake) tracker directory (the image/pdf filename).
$urchinUrl1 = 'http://www.google-analytics.com/__utm.gif?utmwv=4.3&utmn='.$var_utmn.'&utmsr='.$referer.'&utmcs='.$var_utmcs.
'&utmul=en&utmje=0&utmfl=-&utmdt='.$utm_campaign.'&utmhn='.$var_utmhn.
'&utm_source='.$var_utmp.'&utm_medium='.$utm_medium.'&utm_campaign='.$utm_campaign.'&utmr='.$var_referer.
'&utmp='.$var_utmp.'&utmac='.$var_utmac.
'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.
$var_today.'.'.$var_today.'.'.$var_today.
'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.
$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.
'.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D'.
$var_cookie.'.'.'%3B';
// Now fire off the HTTP request
echo "urchinURL1 == ".$urchinUrl1.' '.__FILE__.' '.__LINE__.'<br/>';
return $urchinUrl1;
seems like over kill to me but it works, I tried the code at https://developers.google.com/analytics/devguides/collection/other/mobileWebsites and it doesn't work - the opens and clicks do not register in analytics - at least not on the real time page.
Please help.
I suggest that you build your report query first, I recommend that you use Google Analytics Query Explorer for that.
And next use the reporting API from PHP to transpose the resulting query and extract the data from within your app.