Re: Here's a DB example

From: Date: Fri, 16 Mar 2001 19:14:23 +0000
Subject: Re: Here's a DB example
References: 1 2 3  Groups: php.gtk 
Request: Send a blank email to php-gtk+get-936@lists.php.net to get a copy of this message
Hey, That's done the trick. Regards Martin Cameron GIOT Jean Philippe wrote: > it's really easy in fact : > > command $label->set_text($l); doesn't add text to what have been set before, it > overiddes it! > > this is the corrected function : > > function ret_data(){ > global $label, $entry, $db, $button1, $button2; > $username=$entry->get_text(); > $label->set_text("Connecting to database"); > $sql="select * from statement where username = '$username'"; > $res=$db->query($sql); > > $labeltext=""; > > while($row=mysql_fetch_array($res)){ > $l= ("Username: ".$row["username"].":: > Amount:".$row["amount"]." :: Date:".$row["date"]." > .\n"); > print $l; > $labeltext .= $l."\n"; > } > $label->set_text($labeltext); > } > > the concatenation is done by this line : > > $labeltext .= $l; > > for me it works i hope so for you. > > nb: i'm also a student in medecine (4th year) :-) > > going back to my exams... > > ----- Original Message ----- > From: Martin Cameron <cameron@cameron.co.nz> > To: Tarique Sani <tarique@nagpur.dot.net.in> <root@sanisoft.com>; > <php-gtk@lists.php.net> > Sent: Friday, March 16, 2001 4:20 AM > Subject: Re: [PHP-GTK] Here's a DB example > > > As a relative newbie to this 'art' -gtk - I have tried to hack Tarique's > > script to do a small job - display the results returned from a MySQL > > database query. However I'm having problems getting the array returned into > > the $label variable. It's only displaying the last row. > > > > That's the problem in a nutshell. > > > > Here it is in detail. > > > > The "ret_data" function is like this: > > > > function ret_data(){ > > global $label, $entry, $db, $button1, $button2; > > $username=$entry->get_text(); > > $label->set_text("Connecting to database"); > > $sql="select * from statement where username = '$username'"; > > $res=$db->query($sql); > > file://The query for the default username returns nine rows. > > while($row=mysql_fetch_array($res)){ > > $l= ("Username: ".$row["username"].":: Amount: > > ".$row["amount"]." :: Date:".$row["date"]." > > .\n"); > > file://print to the console, the returned value. > > print $l; > > file://This line only returns the last entry. It doesn't concatenate > > each entry as it does for the console. > > $label->set_text($l); > > } > > } > > > > I suspect I'll have to create a new "label" for each entry returned which > > is not what I want to do - what happens if I've got a large number of > > entries to be returned. > > > > If I can get this function to work, then I'll be able to do a lot of work > > returning values from a MySQL database. > > > > Regards > > Martin Cameron > > > > PS The complete file is as follows: > > > > <? > > dl('php_gtk.so'); > > require('./mysql.inc'); > > $db=new DB_Sql; > > function delete_event(){ > > return false; > > } > > function destroy(){ > > Gtk::main_quit(); > > } > > function show_entry(){ > > global $entry,$button1,$button2; > > $entry->show(); > > $button3->hide(); > > $button2->hide(); > > $button1->show(); > > } > > function ret_data(){ > > global $label, $entry, $db, $button1, $button2; > > $username=$entry->get_text(); > > $label->set_text("Connecting to database"); > > $sql="select * from statement where username = '$username'"; > > $res=$db->query($sql); > > $i=0; > > while($row=mysql_fetch_array($res)){ > > $l= ("Username: ".$row["username"].":: Amount: > > ".$row["amount"]." :: Date: ".$row["date"]." > > .\n"); > > print $l; > > $label->set_text($l); > > $i++; > > } > > } > > > > $window= & new GtkWindow(); > > $window->connect('destroy',destroy); > > $window->connect('delete_event',delete_event); > > $window->set_border_width(10); > > $window->set_title('MySQL Query'); > > $box1=& new GtkVbox(false,10); > > $box1->set_border_width(10); > > $window->add($box1); > > $box1->show(); > > $entry= & new GtkEntry(); > > $entry->set_text('cameron'); > > $entry->select_region(0,10); > > $box1->pack_start($entry); > > $entry->show(); > > $frame=&new GtkFrame('Status'); > > $label=&new GtkLabel("Status Area."); > > $frame->add($label); > > $label->show(); > > $box1->pack_start($frame); > > $frame->show(); > > > > file://Creates button1,connects with appropiate signals and packs > > button1 with box1 > > $button1 = &new GtkButton('Search'); > > $button1->connect('clicked', "ret_data"); > > $box1->pack_start($button1,false); > > $button3=&new GtkButton("Cancel"); > > $button3->connect('clicked',"destroy"); > > $box1->pack_start($button3,true); > > file://Creates button2,connects with appropiate signals and packs > > button2 with box1 > > $button2 = &new GtkButton('Search Again!'); > > $button2->connect('clicked', "show_entry"); > > $box1->pack_start($button2,false); > > > > file://Shows toplevel window and hides button2 > > $window->show_all(); > > $button2->hide(); > > /* Run the main loop. */ > > Gtk::main(); > > ?> > > > > "Tarique Sani " wrote: > > > > > http://www.sanisoft.com/db_ex.zip > > > > > > Here is a completely useless but profusely commented and illustrative > > > example of using a DB with php-gtk, see readme.txt if needed > > > > > > I hope it will be useful to in-duh-viduals like me who are struggling > > > rather successfully to learn GTK ;-) > > > > > > Tarique > > > > > > -- > > > ========================================= > > > B2B Application Providers > > > http://www.sanisoft.com > > > Vortal for Nagpur http://nagpurcity.net > > > ========================================= > > > > > > -- > > > PHP GTK Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-gtk-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-gtk-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > _________________________________________________________ > > Do You Yahoo!? > > Get your free @yahoo.com address at http://mail.yahoo.com

« previous php.gtk (#936) next »