note 599 added to gtk.gtkcombo.constructor.php

[email protected]
Newsgroups php.gtk.webmaster
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.