Re: GtkList update problem

From: Date: Mon, 08 Apr 2002 19:58:29 +0000
Subject: Re: GtkList update problem
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-1764@lists.php.net to get a copy of this message
i do this... while ($users = mysql_fetch_array($sql, MYSQL_ASSOC)) { $myarray = Array (item1, item2) <-- make an array with the same number of entries as colums in your list $list->append($myarray); } dont know if it is the right way - but it works oh - and i use CList (i think List is depreciated/buggy) On Mon, 2002-04-08 at 18:28, NetNITCO Web Dept. wrote: > Hello, I am new to PHP-GTK (about 2 days now) and im working on my first app. I have most of > what i want to do figured out but im stuck on one thing... can you update GtkList from within a > function. The program updates everything else but refuses to update the list. If anyone can help it > would be much appreciated. > > Program as follows: > ______________________________________________________________________ > <? > if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') > dl('php_gtk.dll'); > else > dl('php_gtk.so'); > > function delete_event() > { return false; } > > function destroy() > { Gtk::main_quit(); } > > function update() > { > global $text; > global $list; > global $scrolled_window; > global $box; > global $table; > > // Update the hit count // > $db = mysql_connect("bsdard.web-promo.com", "homepage", > "-------"); > mysql_select_db("netnitcocount",$db); > $info = mysql_fetch_array(mysql_query("SELECT * FROM count_daily ORDER BY day desc LIMIT > 1"), MYSQL_ASSOC); > $hits = $info[visitors]; > mysql_close($db); > $text->set_text("Hits Today: $hits"); > > // Should update the list // > $list->set_selection_mode(GTK_SELECTION_BROWSE); > $db = mysql_connect("bsdard.web-promo.com", "homepage", > "-------"); > mysql_select_db("testdb"); > $sql = mysql_query("SELECT login, timestamp FROM testusers Order By timestamp desc LIMIT > 5"); > while ($users = mysql_fetch_array($sql, MYSQL_ASSOC)) > { > $items[] = &new GtkListItem(date("h:i",$users[timestamp])." - > ".$users[login]); > } > mysql_close($db); > $list->append_items($items); > $list->unselect_all(); > $scrolled_window->set_policy(GTK_POLICY_NEVER, GTK_POLICY_NEVER); > $scrolled_window->add_with_viewport($list); > $box->pack_start($scrolled_window); > } > > // setup the window // > $window = &new GtkWindow(); > $window->connect('destroy', 'destroy'); > $window->connect('delete-event', 'delete_event'); > $window->set_border_width(5); > $window->set_usize(300, 110); > $window->set_title('Webpage Stats'); > $window->set_policy(false, false, false); > > // Set the table // > $table = &new GtkTable(3,4); > $table->set_col_spacings(10); > $table->set_row_spacings(10); > $window->add($table); > > // get the current hit count // > $db = mysql_connect("bsdard.web-promo.com", "homepage", > "--------"); > mysql_select_db("netnitcocount",$db); > $info = mysql_fetch_array(mysql_query("SELECT * FROM count_daily ORDER BY day desc LIMIT > 1"), MYSQL_ASSOC); > $hits = $info[visitors]; > mysql_close($db); > > // Hits Label // > $text = &new GtkLabel(); > $text->set_text("Hits Today: $hits"); > $table->attach($text,0,1,0,1); > > // HBar // > $line = &new GtkHSeparator(); > $table->attach($line,0,1,1,2); > > // Username list // > $box = &new GtkVBox(false, 10); > $box->set_border_width(0); > $list = &new GtkList(); > $list->set_selection_mode(GTK_SELECTION_BROWSE); > $db = mysql_connect("bsdard.web-promo.com", "homepage", > "---------"); > mysql_select_db("testdb"); > $sql = mysql_query("SELECT login, timestamp FROM testusers Order By timestamp desc LIMIT > 5"); > while ($users = mysql_fetch_array($sql, MYSQL_ASSOC)) > { > $items[] = &new GtkListItem(date("h:i",$users[timestamp])." - > ".$users[login]); > } > mysql_close($db); > $list->append_items($items); > $list->unselect_all(); > $scrolled_window = &new GtkScrolledWindow(); > $scrolled_window->set_policy(GTK_POLICY_NEVER, GTK_POLICY_NEVER); > $scrolled_window->add_with_viewport($list); > $box->pack_start($scrolled_window); > $table->attach($box,1,4,0,3); > > // Refresh Button // > $button = &new GtkButton("Refresh"); > $button->connect('clicked', 'update'); > $table->attach($button,0,1,2,3); > > $window->show_all(); > > > Gtk::main(); > ?>

« previous php.gtk.general (#1764) next »