0

Dear all,
Hope you are well.

I have just created a page which list a resort name and all the fitness clubs that are available in that resort.

I would like to register the clubs that are being ticked into a table as separate rows. The table name is called tbl_Club_Resort and it has three fields (id, location_id, club_id).

I know one would need to use loop but not sure where to start. I wonder someone can help please.

Many thanks.
Below is my current code:

---------

<form name="add_item" method="post" action="location_kids_programmes.php" onsubmit="return checkInput(this);">
<div id="error" class="hide"></div>

<table width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td>Resort</td>
	<td>
	  <select name="resort" size="1" class="textInput">
	    <option value="-1" selected>Choose one...</option>
	  <?php
	    $sql = "SELECT id 'location_id', name FROM Location WHERE enabled = 1 ORDER BY name";
		$result = mysql_query($sql) or die(mysql_error());
		while ($row=mysql_fetch_assoc($result))
		{
	  ?>
	      <option value="<?php echo $row['location_id'];  ?>"><?php echo $row['name']; ?></option>
	  <?php
	    }
	  ?>
	  </select>
	</td>
  </tr> 
  <?php
	    $sql = "SELECT id, club_name FROM tblKids_Club WHERE active = 1 ORDER BY club_name";
		$result = mysql_query($sql) or die(mysql_error());
		while ($row=mysql_fetch_assoc($result))
		{
	?>
      <tr>
        <td><?php echo $row['club_name']; ?></td>
	      <td><input type="checkbox" name="<?php echo $row['club_id'];?>"></td>
	      
	    </tr>  
	<?php
	    }
	?>	
  <tr>
    <td></td>
	<td style="text-align: right;">
      <input type="hidden" name="action" value="ins" />  
	  <input type="submit" value="Add" />&nbsp;
	  <input type="button" value="Back" onclick="window.location.href='location_kids_programmes.php'" />
	</td>
  </tr>
</table>
</form>

-----

Thanks again.

Edited by nav33n: Please use [code] [/code] tags to wrap your code for easy readability.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by sourcebits
0

hope this will help

<?php
//page name : addresort.php
//to work on id, location_id, club_id,name,club_name

mysql_connect('localhost','root','');
mysql_select_db('mydb');

if(isset($_POST['save']) && $_POST['save']!=''){
  
foreach($chk1 as $chk){   
  $sql="select * from clubtable where club_id=$chk";
  $rs = mysql_query($sql);	 	
  $row=mysql_fetch_array($rs); 	
  $insert="insert into register_table(id,location_id,club_id,name,club_name) values($row['id'],$row['location_id'],$row['club_id'],$row['name'],$row['club_name'])";
  mysql_query($insert);	
}
  
}
?>
<form action="addresort.php">
<table>
<tr>
<td>id</td><td>Location id</td><td>Club id</td><td>Name</td><td>Club name</td><td>select yo add</td>
<tr>

<?php 
      while($row=mysql_fetch_assoc($rs)){
?>
<tr>
<td><?php print $row['id'];?></td><td><?php print $row['location_id'];?></td><td><?php print $row['club_id'];?></td><td><?php print $row['name'];?></td><td><?php print $row['club_name'];?></td><td><input type="checkbox" name=chk1[<? print $row['club_id']?>]></td>
<tr>
<?php } ?>
</table>

<input type="submit" value="save" name="save">
</form>

Edited by nav33n: Use [code][/code] tags to wrap your code for easy readability.

0

Dear sourcebits,

Many thanks for your reply.
addresort.php only shows a blank page with
<td>id</td><td>Location id</td><td>Club id</td><td>Name</td><td>Club name</td><td>select yo add</td> on.

I don't see any check boxes to save the clubs? Is it because the program is asking for $chk?

Should I have replaced location_kids_programmes.php with addresort.php?

Sorry to be a pain but many thanks for your time.

Regards

0

Please see, we have tested the code along with the database details attached.

<?php
//page name : addresort.php
//to work on id, location_id, club_id,name,club_name

mysql_connect('localhost','root','');
mysql_select_db('mydb');

if(isset($_POST['save']) && $_POST['save']!=''){

foreach($chk1 as $key=>$val){
$sql1="select * from resort_details where club_id=$key";
$rs1 = mysql_query($sql1);
$row=mysql_fetch_array($rs1);

$id=$row['id'];
$loc_id=$row['location_id'];
$club_id=$row['club_id'];
$name=$row['name'];
$club_name=$row['club_name'];

$insert="insert into register_details(id,location_id,club_id,name,club_name) values($id,$loc_id,$club_id,'$name','$club_name')";
mysql_query($insert);
}

}
?>
<form method="post" action="mytest.php">
<table>
<tr>
<td>id</td><td>Location id</td><td>Club id</td><td>Name</td><td>Club name</td><td>select yo add</td>
<tr>

<?php
$sql="select * from resort_details";
$rs = mysql_query($sql);
while($row=mysql_fetch_assoc($rs)){
?>
<tr>
<td><?php print $row['id'];?></td><td><?php print $row['location_id'];?></td><td><?php print $row['club_id'];?></td><td><?php print $row['name'];?></td><td><?php print $row['club_name'];?></td><td><input type="checkbox" name=chk1[<? print $row['club_id']?>]></td>
<tr>
<?php } ?>
</table>

<input type="submit" value="save" name="save">
</form>
############database#### info
--
-- Table structure for table `register_details`
--

CREATE TABLE IF NOT EXISTS `register_details` (
  `id` int(19) NOT NULL AUTO_INCREMENT,
  `location_id` int(19) NOT NULL,
  `club_id` int(19) NOT NULL,
  `name` varchar(50) NOT NULL,
  `club_name` varchar(50) NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `register_details`
--

INSERT INTO `register_details` (`id`, `location_id`, `club_id`, `name`, `club_name`, `date`) VALUES
(1, 1, 4, 'Loca name', 'Club name', '0000-00-00');

-- --------------------------------------------------------

--
-- Table structure for table `resort_details`
--

CREATE TABLE IF NOT EXISTS `resort_details` (
  `id` int(19) NOT NULL AUTO_INCREMENT,
  `location_id` int(19) NOT NULL,
  `club_id` int(19) NOT NULL,
  `name` varchar(50) NOT NULL,
  `club_name` varchar(50) NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `resort_details`
--

INSERT INTO `resort_details` (`id`, `location_id`, `club_id`, `name`, `club_name`, `date`) VALUES
(1, 1, 4, 'Loca name', 'Club name', '2010-06-25'),
(2, 2, 5, 'loc name2', 'lob name 2', '2010-06-04');

Edited by nav33n: Added [code][/code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.