note 599 added to gtk.gtkcombo.constructor.php

From: Date: Mon, 24 Oct 2005 09:57:51 +0000
Subject: note 599 added to gtk.gtkcombo.constructor.php
Groups: php.gtk.webmaster 
Request: Send a blank email to php-gtk-webmaster+get-2856@lists.php.net to get a copy of this message
Here is how to create a combo using a MySQL result quickly. $combo = &new GtkCombo(); $entry = $combo->entry; $list = $combo->list; $list->set_selection_mode( GTK_SELECTION_SINGLE ); $qry = mysql_query( "SELECT id,chrName FROM tblThings" ); $x = 0; while( $row = mysql_fetch_assoc( $qry ) ) { $itmOption = &new GtkListItem(); $lblOption = &new GtkLabel( $row['chrName'] ); $lblOption->set_justify( GTK_JUSTIFY_LEFT ); $lblOption->set_alignment( 0, 0 ); $itmOption->add( $lblOption ); $combo->set_item_string( $itmOption, $row['chrName'] ); $itmOption->set_data( $x, $row['id'] ); $itmOption->connect( "button-press-event", array ( &$this, "on_click" ), $x ); $itmOption->connect( "toggle", array ( &$this, "on_key" ), $x ); $list->add( $itmOption ); $itmOption->show_all(); } Note: In the above examples and the manual example $i ($x in my example) is incremented for some odd reason and it doesnt need to be. Unless you have multiple data values in each GtkListItem that require unique key values, but since there is only one 'id' to each value in your MySQL database $x = 0 is sufficient. http://gtk.php.net:80/manual/en/gtk.gtkcombo.constructor.php

« previous php.gtk.webmaster (#2856) next »