1
urbanspacema
Dropdown select problem with xoopsForm classes

Hello to all
First, I apologize for my English certainly terrible!!

Here's my problem

I am carrying out a form with XOOPS classes for a new module

I have create a SELECT menu (drop down) which takes data from a table.

Table called umus_format and his 2 fields format_id and format_title

drop down displays all values but not showing the values that begin with a number...

ex. CD,DVD,LP are ok 2CD,2DVD,2LP do not appear

Here is the code.

// Controllo se esistono i formati altrimenti non posso creare una recensione e vengo rimandato alla pagina dei formati
$result2 $xoopsDB->query"SELECT count(format_id) as count FROM ".$xoopsDB->prefix("umus_format")."" ) ;
list( 
$count ) = $xoopsDB->fetchRow$result2 ) ;
if( 
$count ) {
    
redirect_header(XOOPS_URL."/modules/umusic/admin/admin_format.php",2,_MI_UMUS_MUSTADDFORMATFIRST);
    exit();
}

$umus_format $xoopsDB->prefix"umus_format" ) ;

$ftree = new XoopsTree($umus_format,"format_id""format_title" ) ;

// Creo la select per mostrare i formati
$format = new XoopsFormSelect_MI_UMUS_REV_SELECTFORMAT "format_id" $format_id ) ;
$treef $ftree->getChildTreeArray"format_id" ) ;



foreach( 
$treef as $leaff ) {
    
$leaff['prefix'] = substr$leaff['prefix'] , , -) ;
    
$leaff['prefix'] = str_replace"." "--" $leaff['prefix'] ) ;
    
$format->addOption$leaff['format_id'] , $leaff['prefix'] . $leaff['format_title'] ) ;
}
//

$my_form->addElement$format ) ;


if I make a normal query to the database I see that all values are inserted correctly

Mysql code

CREATE TABLE umus_format (
  
format_id tinyint(3unsigned NOT NULL auto_increment,
  
format_title varchar(255NOT NULL default '',
  
PRIMARY KEY  (format_id)
TYPE=MyISAM;


INSERT INTO umus_format (format_titleVALUES ('CD');
INSERT INTO umus_format (format_titleVALUES ('2CD');
INSERT INTO umus_format (format_titleVALUES ('DVD');
INSERT INTO umus_format (format_titleVALUES ('2DVD');
INSERT INTO umus_format (format_titleVALUES ('LP');
INSERT INTO umus_format (format_titleVALUES ('2LP');
INSERT INTO umus_format (format_titleVALUES ('12"');
INSERT INTO umus_format (format_titleVALUES ('10"');
INSERT INTO umus_format (format_titleVALUES ('7"');
INSERT INTO umus_format (format_titleVALUES ('Digital');
INSERT INTO umus_format (format_titleVALUES ('Cassette');
INSERT INTO umus_format (format_titleVALUES ('Altro');



which may be the problem? I have perhaps found a bug?

Urban
http://www.ultrasonica.it
http://www.noisecollective.net

2
Catzwolf
Re: Dropdown select problem with xoopsForm classes
  • 2008/5/20 22:33

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Did you check to see if your $treef array has the proper array structure that you want? It looks like $leaff['format_id'] && $leaff['prefix'] . $leaff['format_title'] have been swapped around?

Plus don't use xoopstree, it is a resource hog and will be removed from XOOPS at one point. I would suggest that you look into xoopsObject and use the tree.php class instead with it.

3
urbanspacema
Re: Dropdown select problem with xoopsForm classes

thank you catzwolf_

I'm trying to understand how XoopsObjectTree works

with this code

$umus_categories $xoopsDB->prefix'umus_categories' ) ;
$cat_tree = new XoopsObjectTree($umus_categories'category_id''category_title');
$cat $cat_tree->makeSelBox('category_id''category_title''-- '$category_idtrue);


I see only a empty select box...

debug show this error
Warning: array_keys() [function.array-keys]: The first argument should be an array in file /class/tree.php line 79

you could help me please?

Urban
http://www.ultrasonica.it
http://www.noisecollective.net

4
trabis
Re: Dropdown select problem with xoopsForm classes
  • 2008/5/21 19:01

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Hi, did not tested but, try this:
// Controllo se esistono i formati altrimenti non posso creare una recensione e vengo rimandato alla pagina dei formati
$result2 $xoopsDB->query"SELECT count(format_id) as count FROM ".$xoopsDB->prefix("umus_format")."" ) ;
list( 
$count ) = $xoopsDB->fetchRow$result2 ) ;
if( 
$count ) {
    
redirect_header(XOOPS_URL."/modules/umusic/admin/admin_format.php",2,_MI_UMUS_MUSTADDFORMATFIRST);
    exit();
}

$formats = array();
$result3 $xoopsDB->query"SELECT * FROM ".$xoopsDB->prefix("umus_format")."" ) ;
while (
$myrow $xoopsDB->fetchArray($result)) {
    
$formats[$myrow['format_id']] = $myrow['format_title'];
}

// Creo la select per mostrare i formati
$format_select = new XoopsFormSelect(_MI_UMUS_REV_SELECTFORMAT"format_id");
$format_select->addOptionArray$formats ) ;

//
$my_form->addElement$format_select ) ;


You cannot use tree because you do not have a tree structure on your table. For using that class you must have Id and parent Id. You have a single id so... no tree for you!

5
urbanspacema
Re: Dropdown select problem with xoopsForm classes

work !!!!!!!!
thank you very much

there is only a small error in the code

$result3 $xoopsDB->query"SELECT * FROM ".$xoopsDB->prefix("umus_format")."" ) ; 
while (
$myrow $xoopsDB->fetchArray($result)) { 
    
$formats[$myrow['format_id']] = $myrow['format_title'];


modify
with this

while ($myrow = $xoopsDB->fetchArray($result3)){


tnx Trabis
Urban
http://www.ultrasonica.it
http://www.noisecollective.net

Login

Who's Online

237 user(s) are online (148 user(s) are browsing Support Forums)


Members: 0


Guests: 237


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits