Hallo, people.
I need to add different kinds of sport(tennis, football, racing) in sportsman's profile.
I want to make a lot of checkboxes in Register_user form.
But there are really a lot of different types of sport(nearly 50). So I am afraid to make additionally 50 fields in the Player table. I want to make a separate table Sports. And from one Register form I'm gonna filling two tables: tbl_player(with fields id,name, age, birthplace,...) and tbl_player_sports(id, player_id, sport_id)
Tell me please if it's possible? Thanks.
Page 1 of 1
Kinds Of Sport For A Player checkboxes, form, tables
#2
Posted 26 January 2013 - 09:06 AM
Yes, it is possible. You can view it as like
Posts and Categories and for their relations post_categoires
Posts and Categories and for their relations post_categoires
Player table id name etc Sport table id name player_sport relation table id player_id sport_id
#3
Posted 27 January 2013 - 12:01 PM
PeRoChAk, on 26 January 2013 - 09:06 AM, said:
Yes, it is possible. You can view it as like
Posts and Categories and for their relations post_categoires
Posts and Categories and for their relations post_categoires
Player table id name etc Sport table id name player_sport relation table id player_id sport_id
can I see a working example of a Yii_blog, where blog_posts have categories? In a demo-blog there are no categories for posts
#5
Posted 28 January 2013 - 05:18 AM
I have 3 tables in the database tbl_player, tbl_player_sports and tbl_sports CREATE TABLE IF NOT EXISTS `tbl_player_sports` ( `player_id` int(11) NOT NULL DEFAULT '0', `sport_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`player_id`,`sport_id`), KEY `FK_player_id` (`player_id`), KEY `FK_sport_id` (`sport_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `tbl_player_sports` (`player_id`, `sport_id`) VALUES (15, 1), (15, 2), (17, 2), (17, 3); ALTER TABLE `tbl_player_sports` ADD CONSTRAINT `FK_player_id` FOREIGN KEY (`player_id`) REFERENCES `tbl_player` (`id`) ON DELETE CASCADE, ADD CONSTRAINT `FK_sport_id` FOREIGN KEY (`sport_id`) REFERENCES `tbl_sports` (`id`) ON DELETE CASCADE; CREATE TABLE IF NOT EXISTS `tbl_sports` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ; -- -- Дамп данных таблицы `tbl_sports` -- INSERT INTO `tbl_sports` (`id`, `name`) VALUES (1, 'tennis'), (2, 'football'), (3, 'swimming'); CREATE TABLE IF NOT EXISTS `tbl_player` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `salt` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `sname` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `fname` varchar(128) COLLATE utf8_unicode_ci NOT NULL, `aim` int(1) NOT NULL, `atp_rate` int(11) DEFAULT NULL, `photo` varchar(90) COLLATE utf8_unicode_ci NOT NULL, `profile` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ; INSERT INTO `tbl_player` (`id`, `username`, `password`, `salt`, `email`, `name`, `sname`, `fname`, `aim`, `atp_rate`, `photo`, `profile`) VALUES (15, 'root', '8fabcc92999b55cc343646120f8f547c', '28b206548469ce62182048fd9cf91760', 'we@g.net', 'as', 'we', 'as', 0, 45, '48413086.jpg', NULL), (17, 'zxc', '1f9099ad686311ab046a6510508bff93', '28b206548469ce62182048fd9cf91760', 't@bigmir.net', 'zxc', 'zxc', 'zxc', 0, 345, '1187134.jpg', NULL),
And I have a model for a User with relation
'sports'=>array(self::MANY_MANY, 'Sport','tbl player sports(player id, sport id)'),
#6
Posted 28 January 2013 - 05:19 AM
Dear YII-programmers,
I want to add a group of checkboxes(tennis,swimming,football) to the sportsman's register-form.
Submitting this form user is about to automatically fill tables tbl_user and tbl_player_sports.
So I need to change some code in a view, that corresponds to the register-form.
here is a piece of a working code:
Now, answer me, please. How should I add this checkboxes in this view file?
I want to add a group of checkboxes(tennis,swimming,football) to the sportsman's register-form.
Submitting this form user is about to automatically fill tables tbl_user and tbl_player_sports.
So I need to change some code in a view, that corresponds to the register-form.
here is a piece of a working code:
<div class="row"> <?php echo $form->labelEx($model,'sname'); ?> <?php echo $form->textField($model,'sname'); ?> <?php echo $form->error($model,'sname'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'aim'); ?> <select name="Player[aim]"> <option value="0">find a sparring-partner</option> <option value="1">find a couch</option> <option value="2">challenge a player</option> <option value="3">skills</option> </select> <?php echo $form->error($model,'aim'); ?> </div>
Now, answer me, please. How should I add this checkboxes in this view file?
Share this topic:
Page 1 of 1