php - help with table

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
Mammy1
Forum Newbie
Posts: 1
Joined: Tue Oct 14, 2008 5:19 am

php - help with table

Post by Mammy1 »

Hi all,
I am writing a program that will contain a table.
the table contains days of the week as columns and hours (starting 8 AM until 8 PM) as rows.
What I am trying to do is: When clicking a cell, a new page opens and gives us information regarding the specific day and hour.
My problem is that I can't seem to transfer day and time variables correctly.
I use SESSION and it always transfer the last day and time, no meter which cell I click.

My code:

<div align = 'center'>
<table border = 1 width = '100%' bgcolor = '#DCDCDC' >
<caption><EM><h3>מערכת השעות הסמסטריאלית</h3></EM></caption>
<tr>
<td></td>
<th scope="col">Sun</th>
<th scope="col">Mon</th>
<th scope="col">tue</th>
<th scope="col">wed</th>
<th scope="col">th</th>
</tr>
<tr>
<th scope="row">9:30 - 8:30</th>
<td onclick="<?php move(1,8) ?>" style="cursor:hand"><?PHP setCell(1,8,$courses) ?></td>
<td onclick="<?php move(2,8) ?>" style="cursor:hand"><?PHP setCell(2,8,$courses) ?> </td>
<td onclick="<?php move(3,8) ?>" style="cursor:hand"><?PHP setCell(3,8,$courses) ?> </td>
<td onclick="<?php move(4,8) ?>" style="cursor:hand"><?PHP setCell(4,8,$courses) ?></td>
<td onclick="<?php move(5,8) ?>" style="cursor:hand"><?PHP setCell(5,8,$courses) ?></td>
</tr>
<tr>

etc....

where the function move is:

function move($day,$hour)
{
$_SESSION['day'] = $day;
$_SESSION['hour'] = $hour;
?>kishur('http://localhost/css/workspace/tablecell.php')<?php
}
?>

wherer kishur is in java script:
<script language="javascript">
function kishur(the)
{tab=window.open(the,'tab','width=810, height=490 scrollbars=yes toolbar=no,location=yes,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,align=center')
tab.focus()}
</script>


when on page 'tablecell.php' I do: echo "day = ". $_SESSION['day'];echo "hour = ". $_SESSION['hour'];
I always get:
day = 5
hour = 19
Where 5 is the last Day and 19 is the last hour on the table
Please help me make it work!!!!!
User avatar
kryten
Forum Newbie
Posts: 3
Joined: Tue Oct 14, 2008 7:57 am
Location: Essex, UK

Re: php - help with table

Post by kryten »

Hi,

It seems that you need to pass the variables for day and time as either post or get variables.
The simplest solution is to enter them into the URL and read them through $_GET in your 'tablecell.php' and assign to session variables there if required.
This script will pass the day in the form of 1 to 7 (Sun-Mon) and the time as 8 to 20 (8am - 8pm).

Hope this helps
Garry
Freedom Web Services

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1">
  <tr>
    <td>&nbsp;</td>
    <th scope="col">Sunday</th>
    <th scope="col">Monday</th>
    <th scope="col">Tuesday</th>
    <th scope="col">Wednesday</th>
    <th scope="col">Thursday</th>
    <th scope="col">Friday</th>
    <th scope="col">Saturday</th>
  </tr>
  <?php for($time = 8; $time < 20; $time++) { ?>
  <tr>
    <th scope="row"><?php printf("%01.2f", $time);  ?></th>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=1&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(1, $time, $courses); ?></td>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=2&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(2, $time, $courses); ?></td>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=3&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(3, $time, $courses); ?></td>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=4&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(4, $time, $courses); ?></td>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=5&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(5, $time, $courses); ?></td>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=6&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(6, $time, $courses); ?></td>
    <td onclick="kishur('http://localhost/css/workspace/tablecell.php?day=7&time=<?php echo $time ?>');" style="cursor:crosshair"><?php setCell(7, $time, $courses); ?></td>
  </tr>
  <?php } ?>
  <tr>
</table>
</body>
</html>
<script type="text/javascript">
function kishur(url) {
    tab=window.open(url,'tab','width=810, height=490 scrollbars=yes toolbar=no,location=yes,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,align=center');
    tab.focus();
}
</script>
Post Reply