How to Create a Simple Widget?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

How to Create a Simple Widget?

Post by Chalks »

I would like to create a simple widget that anyone could place on their website. All that it would need to do is update (preferably live, but on refresh is fine too) one piece of data. The number of people who care. Like so:
widget.png
widget.png (5.28 KiB) Viewed 104 times
I want it to either:
query a database on my server or
load data from a php file on my server


Is it possible to do this with php?
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: How to Create a Simple Widget?

Post by Chalks »

This actually turned out to be a lot simpler than I expected it to be.

Code: Select all

<div id="widget">
<object data="http://example.com/widget.php" style="width: 155px; height: 20px;">
</object>
</div>
Anything wrong with doing it that way?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: How to Create a Simple Widget?

Post by s.dot »

What's your widget.php code?

When I needed to do something like that I just used imagestring() to draw on an image and present it through a php script. i.e.: image.php?imageid=xxx
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: How to Create a Simple Widget?

Post by Chalks »

widget.php:

Code: Select all

<body onload="count()">
<div style="width: 170px; height: 26px; background-image: url(widget.png); background-repeat: no-repeat;">
  <span style="position: absolute; top: 4px; left: 15px; font-size: 14px;">
    <span id="count"><?php include 'count.php'; ?></span>
    <a href="http://example.com" target="_parent">People Care about this NOW</a>
  </span>
</div>
</body>
the count() function refreshes the span "count" every 30 seconds with the new count. If javascript is disabled, it doesn't break anything, just stops the dynamic refreshes. The target="_parent" because I decided to switch to using <iframe> instead of <object> because ie doesn't properly support the object tag. Everything validates with a transitional dtd.
Post Reply