Display two records output to one html table row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jtp51
Forum Newbie
Posts: 6
Joined: Mon Aug 25, 2003 4:55 pm
Location: Omaha, Nebraska

Display two records output to one html table row

Post by jtp51 »

Summary:

In helping a college student with a soccer site and I need to be able to display up to four records on one table row. In the web site's playing field reservation application, a registered coach may select a field number one and three at 1:00PM, leaving fields two and four open at that same time.

However, another registered coach may reserve field number two at 1:00 PM, thus leaving field number four open at the same time.


Issue:

The first 1:00PM record displays correctly and "marks" field one and three with a "pending" label at 1:00PM. However, the second 1:00PM record for the reserved field two shows up on a table row, with a "pending" label, directly beneath the first 1:00PM record. This makes sense, since it is two records in the table.

Question:

How do I show both records on one row, since both records are at the same time?

Any help or direction or samples are greatly appreciated!

Stats:

MySQL database
PHP Version 4.2.2

Tables:

#----------------------------
# Table structure for tblScheduleHours - table used to loop through the hours the facility is open each day
#----------------------------
create table tblScheduleHours (
SHID int(2) not null auto_increment,
Hours time not null default '00:00:00',
primary key (SHID))
type=MyISAM;

#----------------------------
# Records for table tblScheduleHours
# Military Time
#----------------------------


insert into tblScheduleHours values
(1, '06:00:00'),
(2, '07:00:00'),
(3, '08:00:00'),
(4, '09:00:00'),
(5, '10:00:00'),
(6, '11:00:00'),
(7, '12:00:00'),
(8, '13:00:00'),
(9, '14:00:00'),
(10, '15:00:00'),
(11, '16:00:00'),
(12, '17:00:00'),
(13, '18:00:00'),
(14, '19:00:00'),
(15, '20:00:00'),
(16, '21:00:00'),
(17, '22:00:00'),
(18, '23:00:00'),
(19, '24:00:00');

#----------------------------
# Table structure for tblSchedule - table used to store reservations
#----------------------------
create table tblSchedule (
SID int(50) not null auto_increment,

ReserveDate date,
TimeID int(2) not null default '0',
Reserveby int(10) not null default '0',
ReservedFlag int(4) not null default '0',
NW char(1),
NE char(1),
SW char(1),
SE char(1),
Trainer int(1) not null default '0',
primary key (SID))
type=MyISAM;

#----------------------------
# Records for table tblSchedule
#----------------------------


insert into tblSchedule values
(1, '2003-08-15', 7, 23, 1, '0', '0', '', '', 1),
(2, '2003-08-15', 7, 23, 1, '', '', '0', '', 0),
(3, '2003-08-20', 7, 23, 1, '', '', '0', '0', 1),
(4, '2003-08-20', 7, 23, 1, '', '0', '', '', 0);

Code:

Code: Select all

<?php

$date = $_POST&#1111;'txtDate'];
$qdate = $_GET&#1111;'qDate'];

if(isset($date))&#123;
	$date = $date;
	$newdate = date("Y-m-d", strtotime($date));
	&#125; else &#123;
	$date = $qdate;
	$newdate = date("Y-m-d", strtotime($date));
&#125;

mysql_select_db($database_connCenter, $connCenter);
//$query_rsGetScheduleHours = "SELECT tblScheduleHours.SHID, tblScheduleHours.Hours, tblSchedule.SID, tblSchedule.ReserveDate, tblSchedule.TimeID, tblSchedule.ReservedFlag, tblSchedule.Reserveby, tblSchedule.NW, tblSchedule.NE, tblSchedule.SW, tblSchedule.SE, tblSchedule.Trainer FROM tblSchedule RIGHT OUTER JOIN tblScheduleHours ON (tblSchedule.TimeID = tblScheduleHours.SHID)";
$query_rsGetScheduleHours = "SELECT * FROM tblScheduleHours";
$rsGetScheduleHours = mysql_query($query_rsGetScheduleHours, $connCenter) or die(mysql_error());
$row_rsGetScheduleHours = mysql_fetch_assoc($rsGetScheduleHours);
$totalRows_rsGetScheduleHours = mysql_num_rows($rsGetScheduleHours);


function writeValue($intValue,$fieldname)&#123;
  if($intValue == '1')&#123;
  		$varWriteValue = "<font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">Reserved</font>";
  &#125; elseif($intValue == '0') &#123;
  		$varWriteValue = "<font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">Pending Res.</font>";
  &#125; else &#123;
		$varWriteValue = "$fieldname: <input name="cb$fieldname" type="checkbox" id="cb$fieldname" value="0">";

  &#125;

  return $varWriteValue;
&#125;
?>



<form action="process_reservation.php" method="post">
                  <table width="700" border="0" cellpadding="2" cellspacing="0">
				  <tr bgcolor="#CCCCCC">
                      <td align="center"><img src="../../images/reservfield/NW.gif" width="100" height="62"></td>
                      <td align="center"><img src="../../images/reservfield/SW.gif" width="100" height="62"></td>
                      <td align="center"><img src="../../images/reservfield/NE.gif" width="100" height="62"></td>
                      <td align="center"><img src="../../images/reservfield/SE.gif" width="100" height="62"></td>
                      <td align="center"><font size="2" face="Arial, Helvetica, sans-serif">Request
                        Trainer:</font></td>
                      <td align="center"><font size="2" face="Arial, Helvetica, sans-serif">Hours:</font></td>
                    </tr>
            <?php
			do &#123;
			mysql_select_db($database_connCenter, $connCenter);
			$query_rsGetReservedTime = sprintf("SELECT * FROM tblSchedule WHERE tblSchedule.TimeID = '%s' AND tblSchedule.ReserveDate ='%s'", $row_rsGetScheduleHours&#1111;'SHID'], $newdate);
			$rsGetReservedTime = mysql_query($query_rsGetReservedTime, $connCenter) or die(mysql_error());
			$row_rsGetReservedTime = mysql_fetch_assoc($rsGetReservedTime);
			$totalRows_rsGetReservedTime = mysql_num_rows($rsGetReservedTime);
			//----------------------------------------
		  	$varStatusCheck = $row_rsGetReservedTime&#1111;'ReservedFlag'];
			//$duplicate;
				do &#123;
				//if($row_rsGetReservedTime&#1111;'TimeID'] != $duplicate)&#123;
				if(!$varStatusCheck == 1)&#123;
			?>
						<tr bgcolor="<?php if ($BRB_rowcounter++%2==0)&#123;?>#FFFFFF<?php &#125;else&#123; ?>#CCCCCC<?php &#125;?>">
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "NW: <input name="cbNW" type="checkbox" id="cbNW" value="0">"; ?></font></td>
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "SW: <input name="cbSW" type="checkbox" id="cbSW" value="0">"; ?></font></td>
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "NE: <input name="cbNE" type="checkbox" id="cbNE" value="0">"; ?></font></td>
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo "SE: <input name="cbSE" type="checkbox" id="cbSE" value="0">"; ?></font></td>
						  <td width="100" align="center"><font size="2" face="Arial, Helvetica, sans-serif">
							<input name="trainer" type="checkbox" id="trainer" value="1">
							</font></td>
						  <td width="100">
							<input name="varDate" type="hidden" value="<?php echo $newdate; ?>">
							<input name="varTime" type="radio" value="<?php echo $row_rsGetScheduleHours&#1111;'SHID']; ?>">
							<font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row_rsGetScheduleHours&#1111;'Hours']; ?></font>                      </td>
						</tr>
                    <?php &#125; else &#123;  ?>
						<tr bgcolor="<?php if ($BRB_rowcounter++%2==0)&#123;?>#FFFFFF<?php &#125;else&#123; ?>#CCCCCC<?php &#125;?>">
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo writeValue($row_rsGetReservedTime&#1111;'NW'],'NW'); ?></font></td>
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo writeValue($row_rsGetReservedTime&#1111;'SW'],'SW'); ?></font></td>
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo writeValue($row_rsGetReservedTime&#1111;'NE'],'NE'); ?></font></td>
						  <td width="120" align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo writeValue($row_rsGetReservedTime&#1111;'SE'],'SE'); ?></font></td>
						  <td width="100" align="center"><font size="2" face="Arial, Helvetica, sans-serif">
							<input name="trainer" type="checkbox" id="trainer" value="1">
							</font></td>
						  <td width="100">
							<input name="varTime" type="radio" value="<?php echo $row_rsGetScheduleHours&#1111;'SHID']; ?>">
							<font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row_rsGetScheduleHours&#1111;'Hours']; ?></font>                       </td>
						</tr>
                    <?php
						&#125;	//end if
						//&#125;	//end if
						//$duplicate = $row_rsGetReservedTime&#1111;'TimeID'];
					&#125; while ($row_rsGetReservedTime = mysql_fetch_assoc($rsGetReservedTime));
					  ?>
                    <?php
					  &#125; while ($row_rsGetScheduleHours = mysql_fetch_assoc($rsGetScheduleHours));
					  ?>
					 <tr>
					 <td colspan="6" align="right"><input name="varDate" type="hidden" value="<?php echo $newdate; ?>"><input name="btnSubmit" type="submit" value="Make Reservation..."></td>
					 </tr>
                  </table>

				  </form>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I hope I understodd you correctly with this reply with ideas... I'm might refer to something else, but the idea would still work in your case.

I have a table simulating 7 days (yes, a week, Mon-Sun).
Table:
id (1-7)
name (user id)
If my boss (with name BOB) wants to book me on Mondays and Thursdays, he clicks those two days, and BOB gets inserted into the table at id 1 and 4.
My chef books me on Saturday, hence Cheffy gets inserted into the table at id 6.

During a 'select * from table' i would get either BOB, Cheffy or NULL. With this information I can do whatever I want for example;

Code: Select all

<?php
echo '<table><tr>';
// NULL is the same as booked.
 if (empty($row[$username])) { echo '<td>vacant</td>'; } else { echo '<td>'.$row['username'].'</td>'; }
echo '</tr></table>';
?>
If I didn't understand correctly, sorry.
jtp51
Forum Newbie
Posts: 6
Joined: Mon Aug 25, 2003 4:55 pm
Location: Omaha, Nebraska

Your on the right track.

Post by jtp51 »

Thats correct, now I just need to write the data on one table row, instead of a table row for each of the three in your example. Thank you for your response, but I am still unable to solve the problem.
Post Reply