Help me with the WebAPI Please

Hey, as you can see I am having some problems displaying my stats:

http://getsomecashonline.com/whatpulse/about

The sidebar is where I want the stats to be displayed.

I only want it to show my Username, Total Keys, Clicks, Miles, and my world rank.

Could you please explain to me how to display this, as I am confused with how to use the files etc supplied on the webAPI on the main website.

Thanks a lot. :slight_smile:

Righo, just finished the facebook app so take a look at this. I decided against using the script that was available and wrote my own, although it’s not brilliant it does the job :stuck_out_tongue:

[php]<?php

$userid = $_GET['id'] ? $userid = $_GET['id'] : exit("User ID can't be 0.");
$link = file('http://whatpulse.org/api/user.php?UserID='. $userid);
$x = 0;

$output = array( array(3, 4, 5, 10, 11, 12), array("User ID", "Account Name", "Country", "Total Keys", "Total Mouse Clicks", "Total Miles"));
!empty($link[$output[0][0]]) ? '' : exit("Invalid user ID. Please check and try again.");

while ($x < count($output[0])) 
{
	$line = strip_tags($link[$output[0][$x]]);
	$x == 2 ? $line = " <img src=\"images/".str_replace(" ", "", $line).".png\">" . $line : ($x == 3 || $x == 4 ? $line = number_format($line) : ($x == 5 ? $line = number_format($line, 3) : '')) ;
	echo "<b>".$output[1][$x]."</b>: ".$line."<br>";
	$x++;
}

?>[/php]

Just change $userid to match your whatpulse user ID and it will display your User ID, Account name, total keys, clicks and miles as well as your country (not in that order).

Cheers dude, should I leave the $ before the user ID?

EDIT:

[quote] $userid = $_GET[‘id’] ? $userid = $_GET[‘id’] : exit(“User ID can’t be 0.”);
$link = file(‘http://whatpulse.org/api/user.php?UserID=’. 247255); [/quote]

That just displays:
User ID can’t be 0

Remove the full stop? I really should of studied my 700 page PHP book. :stuck_out_tongue:

Change it to:

[php]
$userid = 247255; // 247255 is your specific user id
[/php]

The code i gave you was to be used to get any record so you could actually remove the $userid; line and change the $link; line to read:

[php]
$link = file(‘http://whatpulse.org/api/user.php?UserID=’. 247255);
[/php]

kk, gotta wait for my site to update now, for some really fucking strange reason the sidebar doesnt update for ages. =/

K its updated.

Invalid user ID. Please check and try again.

Not sure what I did wrong:

[quote]

<?php $userid = 247255; // 247255 is your specific user id $x = 0; $output = array( array(3, 4, 5, 10, 11, 12), array("User ID", "Account Name", "Country", "Total Keys", "Total Mouse Clicks", "Total Miles")); !empty($link[$output[0][0]]) ? '' : exit("Invalid user ID. Please check and try again."); [/quote] Thats the code I got going.

[php]

<?php $link = file('http://whatpulse.org/api/user.php?UserID=247255'); $x = 0; $output = array( array(3, 4, 5, 10, 11, 12), array("User ID", "Account Name", "Country", "Total Keys", "Total Mouse Clicks", "Total Miles")); !empty($link[$output[0][0]]) ? '' : exit("Invalid user ID. Please check and try again."); while ($x < count($output[0])) { $line = strip_tags($link[$output[0][$x]]); $x == 2 ? $line = " " . $line : ($x == 3 || $x == 4 ? $line = number_format($line) : ($x == 5 ? $line = number_format($line, 3) : '')) ; echo "".$output[1][$x].": ".$line."
"; $x++; } ?>

[/php]

Should work

Works perfectly. Only thing not displaying is the GB flag image, but its all good. Thanks a lot dude. Look forward to seeing the facebook App :smiley:

Heres the sidebar in action:

http://getsomecashonline.com/whatpulse/

OOh images won’t work properly unless either A: You upload them all to your website or B: You just link them to the directory where they are saved on my website (Which is a hell of a lot easier xD)

So change the following line:
[php]
$x == 2 ? $line = " <img src=“images/”.str_replace(" “, “”, $line).”.png">" . $line : ($x == 3 || $x == 4 ? $line = number_format($line) : ($x == 5 ? $line = number_format($line, 3) : ‘’)) ;
[/php]

To read:
[php]
$x == 2 ? $line = " <img src=“http://phpbox.co.uk/apps/Whatpulse/Images//".str_replace(" “, “”, $line).”.png”>" . $line : ($x == 3 || $x == 4 ? $line = number_format($line) : ($x == 5 ? $line = number_format($line, 3) : ‘’)) ;
[/php]

And it should work perfectly.

I’m gonna rewrite the code as well to make it specific to you, since it’s a bit bloated for just one user.

You dont have to go rewriting it all dude, its perfect. Just gonna change this image here quick :smiley:

lol too late xD

[php]

<?php $link = file('http://whatpulse.org/api/user/php?UserID=247255'); $x = 0; $output = array( array(4, 5, 10, 11, 12, 17), array("Account Name", "Country", "Total Keys", "Total Mouse Clicks", "Total Miles", "World Rank")); while($x < count($output[0])) { $line = strip_tags($link[$output[0][$x]]); $x == 1 ? $line = "" . $line : ($x == 2 || $x == 3 ? $line = number_format($line) : ($x == 5 ? $line = number_format($line, 3) : '')); echo "".$output[1][$x].": ".$line."
"; $x++; } ?>

[/php]

Will show: Username, Country, Total Keys, Total Mouse Clicks, Milage, World Rank (In said order). Also the image is now a direct link to the UK flag since it’s static.

Nice one man, haha. Waiting for it to update. World Rank too. :smiley:

No problem, allthough i have just found one small problem with it :slight_smile:

The line:
[php]
$x == 1 ? $line = "<img src=“http://phpbox.co.uk/apps/Whatpulse/Images/UnitedKingdom.png>” . $line : ($x == 2 || $x == 3 ? $line = number_format($line) : ($x == 5 ? $line = number_format($line, 3) : ‘’));
[/php]

Needs to be changed to:
[php]
$x == 1 ? $line = "<img src=“http://phpbox.co.uk/apps/Whatpulse/Images/UnitedKingdom.png>” . $line : ($x == 2 || $x == 3 ? $line = number_format($line) : ($x == 4 ? $line = number_format($line, 3) : ‘’));
[/php]

(Very small change, see if you can spot it xD). At the moment your world rank is being shown to three decimal places :stuck_out_tongue: The above code will fix it lol

Something went a bit wrong I think. Only this shows now:

WhatPulse Stats
Account Name: Xtr3me
Country: View Profile

[CODE]<?php

$link = file('http://whatpulse.org/api/user/php?UserID=247255');
$x = 0;

$output = array( array(4, 5, 10, 11, 12, 17), array("Account Name", "Country", "Total Keys", "Total Mouse Clicks", "Total Miles", "World Rank"));

while($x < count($output[0]))
{
    $line = strip_tags($link[$output[0][$x]]);
    $x == 1 ? $line = "<img src=\"http://phpbox.co.uk/apps/Whatpulse/Images/UnitedKingdom.png>" . $line : ($x == 2 || $x == 3 ? $line = number_format($line) : ($x == 4 ? $line = number_format($line, 3) : '')); 
    echo "<b>".$output[1][$x]."</b>: ".$line."<br>";
    $x++;
}

?>
View Profile[/CODE]

Whoops, forgot a bloody " :stuck_out_tongue:

[php]

<?php $link = file('http://whatpulse.org/api/user/php?UserID=247255'); $x = 0; $output = array( array(4, 5, 10, 11, 12, 17), array("Account Name", "Country", "Total Keys", "Total Mouse Clicks", "Total Miles", "World Rank")); while($x < count($output[0])) { $line = strip_tags($link[$output[0][$x]]); $x == 1 ? $line = "" . $line : ($x == 2 || $x == 3 ? $line = number_format($line) : ($x == 4 ? $line = number_format($line, 3) : '')); echo "".$output[1][$x].": ".$line."
"; $x++; } ?>

[/php]

There was a problem with the url to the image, fixed now though - sorry about that :slight_smile:

Haha, tut tut Smithy :stuck_out_tongue: Cheers. :smiley:

Hehe thanks man, works perfectly.

I also realised the problem with my site not updating isnt the site, its Google Chrome. It seems to not want to update for atleast an hour. But, I can’t go back to Firefox because Im suffering from a cookie virus and my cookies get deleted every time i close firefox eventhough the settings are all set to keep cookies active. I swear, its getting closer and closer to requiring a reformat. May end up going to Windows 7 very soon :stuck_out_tongue:

Well if you do go to windows 7 you won’t be dissapointed :stuck_out_tongue:

Try running Spybot S&D or whatever it’s called (google it), works wonders!

Yeh ive tried everything, but things are just majorly screwed. Its been a year and a half now since last reformat. Ive done bloody well to be honest. :stuck_out_tongue_winking_eye: