Widget resources, widgets for download, tutorials and more at widgipedia.com
Popular Tags:

action adventure alfanet apple arcade blog blogs business cars clock dashboard drive flash free fun game games garageband google idvd ilife imovie iphoto islam iweb kpop mac macwidgets mario music news platform play puzzle search searchfree shoot sports strategy thedashboard tvwidgets websearch widget widgetindex widgettv
Log in to Widgipedia
The Widgipedia Forum : Widget Development
Discussions about widget technologies, platforms, news, ideas - the place that can shape the future of the widgets.
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
bloke
(IP Logged)
December 12, 2006 01:40AM

messagemit widget auf daten zugreifen
hi folks,
i want to make a widget, that fetches content form .php code.

my database:

<?
include("config.inc.php");

mysql_query ("CREATE TABLE widget_data (
ID INT AUTO_INCREMENT,
Q_News VARCHAR(70),
Inhalt VARCHAR(70),
FULLTEXT (Q_News, Inhalt),
PRIMARY KEY (ID)
)TYPE=MyISAM;");


?>


and the script for fetching the data:


<?php
echo "<font size='5'>Widget</font>\n";

if(!isset ($_GET["start"])) $start = 0;
else $start = $_GET["start"];
$sql2 = "SELECT Q_News FROM widget_data";
$res2 = mysql_query($sql2) OR die(mysql_error());
$anzahl = mysql_num_rows($res2);
$sql = "SELECT
Q_News,
Inhalt,
FROM
widget_data
ORDER BY
Datum DESC LIMIT $start, 1";
$result = mysql_query($sql) OR die(mysql_error());
echo "<p>Einträge in der Datenbank: ".$anzahl."</p>\n";
echo "<hr size='1' width='75%' align='left'>\n";

$seiten = ceil($anzahl/1);

for($i=1;$i<=$seiten;$i++) {

$start = $i*1-1;

echo "<a href=\"data_widget.php?start=$start\">Seite $i</a>";
if($i < $seiten)
{echo " | ";}

}

echo "<hr size='1' width='75%' align='left'>\n";

while($row = mysql_fetch_assoc($result)) {


echo "News: ".$row['Q_News']."\n";

echo "<br><hr size='1' width='70%' align='left'><br>";

echo "Kunden Inhalt: ".$row['Inhalt']."\n";

echo "<br><hr size='1' width='70%' align='left'><br>";
}
?>


i am very thankful for every hint, how i can start the widget-script! and this is my widget-script so far (without any functions):

<?xml version="1.0" encoding="utf-8"?>
<widget version="1.0" minimumVersion="3.1" author="bloke">
<debug>off</debug>

<window title="Widget">
<name>mainWindow</name>
<width>454</width>
<height>340</height>
<visible>1</visible>
<shadow>0</shadow>

<image src="Resources/back.png">
<name>back</name>
<hOffset>20</hOffset>
<vOffset>56</vOffset>
<opacity>255</opacity>
</image>

<image src="Resources/rand.png">
<name>rand</name>
<hOffset>45</hOffset>
<vOffset>140</vOffset>
<opacity>255</opacity>
</image>

<image src="Resources/content.png">
<name>content</name>
<hOffset>50</hOffset>
<vOffset>144</vOffset>
<opacity>128</opacity>
</image>

<image src="Resources/logo.png">
<name>logo</name>
<hOffset>259</hOffset>
<vOffset>66</vOffset>
<opacity>255</opacity>
</image>

</window>

</widget>



so, i just need a function that fetches the two varible form the .php script gives them out in my widget!

greetings
bloke

  
kaintze
(IP Logged)
December 14, 2006 03:13PM

messageRe: mit widget auf daten zugreifen
I'm not sure I understand what you are trying to do. My assumptions are that:
1. you have a news database in MySQL
2. you have a PHP page that pulls the news from the database and displays them in a paginated way
3. you want to build a widget that displays the news

Can you please clarify the following:
1. do you use the PHP page on a website, or you're using the page only from your widget? If you want to build a server page for your widget it's better to generate an XML rather than a HTML code
2. does your widget display one news item or more at the same time?
3. what kind of navigation does your widget have? prev/next and random?
4. what news does the widget display when you first open it? the first item from the database? the last visited item? a random news?
5. can you post a screenshot of your widget? it's not very clear from the code how it looks

kaintze

  
kaintze
(IP Logged)
December 14, 2006 03:21PM

messageRe: mit widget auf daten zugreifen
BTW - to see this post in German you can use an English to German online translator such as Altavista's Babel Fish.
This page in German

kaintze

  
bloke
(IP Logged)
December 15, 2006 01:02AM

messageRe: mit widget auf daten zugreifen
1. itīs just used for teh widget, and i have to put the variables out in XML (but iīm new to XML, so it takes a little time to learn!)!!
2.+ 4. it display two different news at once, as seen in the screenshot! but the database only allows one dataset entrie at the time. so no problem with the output winking smiley
3. donīt know...i`m new to XML, still have to find out! wich one better for my needs?
5.http://www.krog-o-mat.de/images/screen.jpg

big THX for your help (that i hopefullyget winking smiley )..
bloke

  
bloke
(IP Logged)
December 15, 2006 01:06AM

messageRe: mit widget auf daten zugreifen
the translators arenīt the best..
...itīs easier to understand in englishgrinning smiley

any way, thx for your interest in my problem, VERY NICE of you...
bloke

  
bloke
(IP Logged)
December 15, 2006 05:29AM

messageRe: mit widget auf daten zugreifen
hi folks,
the XML-Output is done!
but i stillo need help to fetch the data with my widget!!
any suggestions ?? would be very helpful for me!

new scriptcode for an XML-output:


<?php
echo "<font size='5'>Widget_Datenbank</font>\n";
echo "<p>\n";
echo "<a href=\"data_widget.php?section=add\"><b>In die Datenbank schreiben</b></a>\n";
echo "<p>\n";


$sql = "SELECT
ID,
News,
Kunde
FROM
widget_data
ORDER BY
ID DESC;";
$result = mysql_query($sql) OR die(mysql_error());

echo "<hr size='1' width='75%' align='left'>\n";

while($row = mysql_fetch_assoc($result)) {

$xmlString = "";
$xmlString .= '<response>' .
'<data>';

$xmlString .= $row['News'];
$xmlString .=

'</data>' .
'</response>';


$xmlString2 = "";
$xmlString2 .= '<response>' .
'<data>';

$xmlString2 .= $row['Kunde'];
$xmlString2 .=

'</data>' .
'</response>';

echo "News: ".$xmlString;
echo "<br>\n";
echo "Inhalt: ".$xmlString2;
echo "<br><hr size='1' width='70%' align='left'><br>";
}
?>



greetings,
bloke

  
Adrian Citu
(IP Logged)
December 15, 2006 08:26AM

messageRe: mit widget auf daten zugreifen
Hello bloke,

There are two things to discuss here. First is how your widget will receive data through XML; the second is that your server must also send the correct headers to the widget.

On 1, here is a sketch for a framework for the communication with server.


var objRequest = new XMLHttpRequest();

// call this to retrieve data from server
function getFromServer()
{
var strURL = "http://www.yourserver.com/api.php";

// specify a callback function to be called by the engine when
// data becomes available on the connection
objRequest.onreadystatechange = onDataReceived;

// initiate the request
objRequest.open( "GET", strURL, true );
objRequest.send();
}

// this is the callback function - will be called when data becomes available
function onDataReceived()
{
// only do something if everything OK
if (objRequest.status == 200)
{
// use XPath support for parsing the retrieved XML
var element = doc.evaluate( "response/news/data" );

// SEEME - double check this syntax - not sure if it's accurate!
for (var entry in element.item(0).childNodes)
{
text = entry.item(0).data;
// do something with the text
...
}
}
}




Now on 2: the code that you pasted above doesn't return "pure" XML and doesn't specify headers such as "text/xml". To fix this, you should probably format the server's output such as:


<?xml version="1.0" encoding="UTF-8"?>
<response>
<news>
<data>
...
</data>
</news>
<inhalt>
<data>
...
</data>
</inhalt>
</response>



and also send the headers with a call like below:


header("Content-type: text/xml;");

  
bloke
(IP Logged)
December 17, 2006 05:57AM

messageRe: mit widget auf daten zugreifen
thank you very much, the xml-output works so far..
.. but where do i put my script in the widget to get the data displayed ?!?


<?xml version="1.0" encoding="utf-8"?>
<widget version="1.0" minimumVersion="3.1" author="bloke">
<debug>off</debug>

<window title="Widget">
<name>mainWindow</name>
<width>454</width>
<height>340</height>
<visible>1</visible>
<shadow>0</shadow>

<image src="Resources/back.png">
<name>back</name>
<hOffset>20</hOffset>
<vOffset>56</vOffset>
<opacity>255</opacity>
</image>

<image src="Resources/rand.png">
<name>rand</name>
<hOffset>45</hOffset>
<vOffset>140</vOffset>
<opacity>255</opacity>
</image>

<image src="Resources/content.png">
<name>content</name>
<hOffset>50</hOffset>
<vOffset>144</vOffset>
<opacity>128</opacity>
</image>

<image src="Resources/logo.png">
<name>logo</name>
<hOffset>259</hOffset>
<vOffset>66</vOffset>
<opacity>255</opacity>
</image>

</window>

</widget>



THX for the help, you brought me an step forward smiling smiley

greetings
bloke

  
Adrian Citu
(IP Logged)
December 18, 2006 03:28AM

messageRe: mit widget auf daten zugreifen
bloke Wrote:
-------------------------------------------------------
> thank you very much, the xml-output works so
> far..
> .. but where do i put my script in the widget to
> get the data displayed ?!?

Hi bloke,

Assuming that you want the data automatically fetched when your widget starts, you should include the JavaScript code from my previous post in the "OnLoad" handler of your widget, like below:


<?xml version="1.0" encoding="utf-8"?>
<widget version="1.0" minimumVersion="3.1" author="bloke">
<debug>off</debug>

...

<action trigger="onLoad"><![CDATA[

var objRequest = new XMLHttpRequest();

// call this to retrieve data from server
function getFromServer()
{
var strURL = "http://www.yourserver.com/api.php";

// specify a callback function to be called by the engine when
// data becomes available on the connection
objRequest.onreadystatechange = onDataReceived;

// initiate the request
objRequest.open( "GET", strURL, true );
objRequest.send();
}

// this is the callback function - will be called when data becomes available
function onDataReceived()
{
// only do something if everything OK
if (objRequest.status == 200)
{
// use XPath support for parsing the retrieved XML
var element = doc.evaluate( "response/news/data" );

// SEEME - double check this syntax - not sure if it's accurate!
for (var entry in element.item(0).childNodes)
{
text = entry.item(0).data;
// do something with the text
...
}
}
}

getFromServer();

]]></action>

...

</widget>


Note that the "action" tag must be included in the "widget" tag and outside of "window" tag.

Best,
Adrian

  
bloke
(IP Logged)
December 21, 2006 12:08AM

messageRe: mit widget auf daten zugreifen
Thank you, after a little research on the httpRequest it works !!
thx for your help and patience!!

merry christmas and a happy new year spinning smiley sticking its tongue out

  


Sorry, only registered users may post in this forum.
Check out our sister site Dealio for Cyber Monday Deals and Nordstrom Coupons.
This forum powered by Phorum.