Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Table rows within PHP itereation not rendering properly

    I can't figure out while the table rows and columns are not display as intended. I have tried everything I could but no solution yet. I'm new to PHP/Mysql.

    What I actually wanted to see as the output is something like this:

    Code:
         $days_of_week_rows['week_day']
    $period_rows['period']   $class_rows['class']  $time_rows['time']
    $period_rows['period']   $class_rows['class']  $time_rows['time']
    $period_rows['period']   $class_rows['class']  $time_rows['time']
    $period_rows['period']   $class_rows['class']  $time_rows['time']
    But instead I see something like this:
    Code:
         $days_of_week_rows['week_day']
    $period_rows['period']
    $period_rows['period']
    $period_rows['period']
    $period_rows['period'] 
    $class_rows['class']  
    $class_rows['class']
    $class_rows['class']
    $class_rows['class']     
    $time_rows['time']
    $time_rows['time']
    $time_rows['time']
    $time_rows['time']
    PHP Code:
    ?>
    <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="1px">
    <?php
    $days_of_week_count 
    1;
                while(
    $days_of_week_count 6)
                {
                    
    $select_days_of_week "SELECT week_dayID, week_day FROM week_day
                                            WHERE week_dayID = '"
    .$days_of_week_count."'";
                    
    $result_days_of_week mysql_query($select_days_of_week) or die('Couldn\'t select from the week_day table' mysql_error());
                    while(
    $days_of_week_rows mysql_fetch_array($result_days_of_week))
                    {
                        
    $week_dayID $days_of_week_rows['week_dayID'];
                        echo 
    "<tr><td colspan='3'>" $days_of_week_rows['week_day'] . "</td></tr>";
                           
    //Select information from period
                            
    $period_select "SELECT period FROM table_period
                                               INNER JOIN table_relate
                                                 ON table_period.periodID = table_relate.periodID
                                              WHERE teacherID = '"
    .$teacherID."' AND week_dayID = '".$week_dayID."'";
                            
    $period_result mysql_query($period_select) or die('Couldn\'t select from table_period ' mysql_error());
                            
                            while(
    $period_rows mysql_fetch_array($period_result))
                            {    
                                echo 
    "<tr><td>" .$period_rows['period']. "</td></tr>";
                                
                            }
                            
                            
    //Select information from class
                            
    $class_select "SELECT class FROM table_class
                                               INNER JOIN table_relate
                                                 ON table_class.classID = table_relate.classID
                                              WHERE teacherID = '"
    .$teacherID."' AND week_dayID = '".$week_dayID."'";
                            
    $class_result mysql_query($class_select) or die('Couldn\'t select from table_class ' mysql_error());
                            while(
    $class_rows mysql_fetch_array($class_result))
                            {
                                echo 
    "<tr><td>" .$class_rows['class']. "</td></tr>";
                            }
                            
                            
    //Select information from time
                            
    $time_select "SELECT time FROM table_time
                                               INNER JOIN table_relate
                                                 ON table_time.timeID = table_relate.timeID
                                              WHERE teacherID = '"
    .$teacherID."' AND week_dayID = '".$week_dayID."'";
                            
    $time_result mysql_query($time_select) or die('Couldn\'t select from table_time ' mysql_error());
                            while(
    $time_rows mysql_fetch_array($time_result))
                            {
                                echo 
    "<tr><td>" .$time_rows['time']. "</td></tr>";
                            }
                            
                    }
                        
                    
    $days_of_week_count $days_of_week_count  1;
                }
                echo 
    "</table>";
    I hope my question is clear enough? Please help. Thanks


    Here is the HTML output source code as wedev1958 as me to
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    >
    <
    html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <
    head>
      <
    meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <
    title>Welcome to UPSS Add a Teacher's Time Table</title>
      <link rel="stylesheet" href="../../css/add_teacher_complete.css" type="text/css" />

      <body>
        <div id="header">
          <div id="left_header_content">

            <p class="school_name">University Preparatory Secondary School (UPSS)</p>
            <p class="school_slogan">Knowledge & Virtue.</p>
          </div>
        </div>
          <div id="wrapper">
            <p class="heading">Preview Newly Added Teacher</p>

            <div id="main_content">
              <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="2px">
                           <tr><td colspan='
    3'>Monday</td></tr><tr><td>1</td></tr><tr><td>3</td></tr><tr><td>5</td></tr><tr><td>8</td></tr><tr><td>JS 1 Diamond</td></tr><tr><td>JS 1 Silver</td></tr><tr><td>JS 1 Silicon</td></tr><tr><td>JS 2 Mercury</td></tr><tr><td>8:10am - 8:55am</td></tr><tr><td>9:40am - 10:25am</td></tr><tr><td>11:10am - 11:55am</td></tr><tr><td>1:50pm - 2:30pm</td></tr><tr><td colspan='3>
               </
    table>

            </
    div>
          </
    div>
        </
    div>
      </
    body>
    </
    html
    Last edited by sality63; 03-04-2012 at 12:45 PM.

  • #2
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    It would help if you post the actual html your php code is creating. You can see the html by "View Source" in your browser. It should then be fairly easy to see which line in your php code is causing the problem.

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Who is coming to the rescue? Any help?

  • #4
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    post the html your php code generates and it should then be fairly easy to see which line in your php code is causing the problem.

  • #5
    New Coder
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I re-edited my orginal post, please check it. Thanks

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Look closely at your table formatting. You say you want 3 columns (cells per row) in your output, yet NONE of your rows has 3 columns.

  • #7
    New Coder
    Join Date
    Oct 2011
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    @litebearer; that was why I posted the code. I cannot get those three coloumns in a row within my PHP code. Please I need help. See the PHP code and help me point out where I'm doing it wrong. I'm getting a bit fustrated with the replies.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •