Passing variables between functions

From: Date: Wed, 21 Mar 2001 19:59:06 +0000
Subject: Passing variables between functions
Groups: php.gtk 
Request: Send a blank email to php-gtk+get-1058@lists.php.net to get a copy of this message
Below is a program for accessing a MySQL database, using panes. However, I can't get the "create_list" function to pick up the $entry variable using $entry->get_text(); Can someone help. <? dl('php_gtk.so'); include('./mysql.inc'); $db = new DB_Sql; function destroy(){ Gtk::main_quit(); } function create_list(){ global $window, $vapned, $list, $text, $labeltext, $labelname, $entry; $vbox = & new GtkVbox(FALSE,10); $vbox->set_border_width(10); $scrolled_window = & new GtkScrolledWindow(NULL,NULL); $scrolled_window->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); $scrolled_window->set_usize(400,500); $vbox->pack_start($scrolled_window, TRUE,TRUE,0); $scrolled_window->show(); if($username == ''){ $username = "phkfoste"; }else{ ---> $username = $entry->get_text; //This is the line that should be picking up the username ente4red into the text entry box but it ain't } $titles=array("Name","Amount","Date"); $list=& new GtkClist(3,$titles); $sql="select * from statement where username = '$username'"; $db = new DB_Sql; $res=$db->query($sql); $labelname=$username; $j=mysql_num_rows($res); print $j."\n"; $labeltext = ''; $i=0; while($row=mysql_fetch_array($res)){ $u=$row["username"]; $a=$row["amount"]; $d=$row["date"]; print $u."\t".$a."\t".$d."\n"; $labeltext[] .= $u; $labeltext[] .= $a; $labeltext[] .= $d; $list->append($labeltext); unset($labeltext); $i++; } $labelname='$username'; $list_item = & new GtkListItem($labelname); $list->set_text(0,0,$labelname); $list_item->show(); $list->set_selection_mode(GTK_SELECTION_SINGLE); $list->set_shadow_type(GTK-SHADOW_OUT); $list->column_titles_active(); $list->column_titles_show(); $list->set_column_auto_resize(2,TRUE); $list->set_column_width(0,100); $list->set_column_width(1,100); $list->set_column_width(2,100); $scrolled_window->add_with_viewport($list); $button = &new GtkButton('Close'); $button->connect_object('clicked',"destroy"); $vbox->pack_start($button, false); $vbox->show(); $list->show_all(); return $vbox; } function create_text(){ global $window, $vpaned, $list, $text,$labeltext,$labelname,$entry; $table = & new Gtktable(2,2,FALSE); $entry = & new GtkEntry(); $entry->set_usize(0,30); $entry->set_uposition(15,0); $entry->set_text(""); $entry->select_region(0,10); $entry->set_position(0); $table->attach($entry,0,1,0,1, GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0,0); $entry->show(); $hscrollbar = & new GtkHScrollbar($entry->hadj); $table->attach($hscrollbar,0,1,1,2,GTK_EXPAND | GTK_FILL, GTK_FILL,0,0); $hscrollbar->show(); $vscrollbar = & new GtkVScrollbar($entry->vadj); $table->attach($vscrollbar,1,2,0,1,GTK_EXPAND | GTK_FILL, GTK_FILL,0,0); $vscrollbar->show(); $entry->connect("activate",'create_list',$entry); return $table; $button = & new GtkButton("close"); $button->connect_object("clicked","destroy"); $vbox->pack_start($button, false); } $window = & new GtkWindow(); $window->set_title("Paned Window"); $window->connect("destroy","destroy"); $window->set_border_width(10); $window->set_usize(450,500); $vpaned = & new GtkVPaned(); $window->add($vpaned); $vpaned->set_handle_size(10); $vpaned->set_gutter_size(15); $vpaned->show(); ---> $entry = create_text(); //This is the line that calls the create_text function $vpaned->add1($entry); $entry->show(); ---> $list = create_list(); //This is the line that calls the create_list function $vpaned->add2($list); $list->show(); $window->show_all(); Gtk::main(); ?> Regards Martin Cameron

« previous php.gtk (#1058) next »