Yii Framework Forum: Kinds Of Sport For A Player - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Kinds Of Sport For A Player checkboxes, form, tables

#1 User is offline   tonny 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-December 12

Posted 26 January 2013 - 06:37 AM

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.
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 579
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

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
Player table
id name etc

Sport table
id name

player_sport relation table 

id player_id sport_id

Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   tonny 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-December 12

Posted 27 January 2013 - 12:01 PM

View PostPeRoChAk, 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
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
0

#4 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 579
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 28 January 2013 - 01:20 AM

I think, you can find the code in docs.

You can check it here
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#5 User is offline   tonny 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-December 12

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)'),
0

#6 User is offline   tonny 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-December 12

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:
<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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users