R
R
Roman Sergeev2017-05-16 09:01:02
PHP
Roman Sergeev, 2017-05-16 09:01:02

Display only table headers. What is the problem?

There is such a table:
0df84e6f64174c47ba0c5e9087aa7e81.jpg
now I am making an output through php to the site

<?php
$db_host = 'localhost';
$db_name = 'schedule';
$db_username = 'root';
$db_password = '';
$db_table_to_show = 'Exam_schedule';

$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
//------------------------------------------------------
$mysqli->query('SET NAMES utf8');
$result = $mysqli->query('SELECT * FROM ' . $db_table_to_show );
$qr_results = array(
  'Дисциплина' => array(),
  'Дата экзамена' => array(),
  'Время экзамена' => array(),
  'Аудитория' => array(),
  'Преподаватель' => array()
);
$mon_rows = 0; $tue_rows = 0;$thu_rows = 0;$wed_rows = 0;$fri_rows = 0;
while ($row = $result->fetch_assoc()){
    switch($row['Day']){
      case 'Дисциплина':
        $qr_results['Дисциплина'][] = $row;
        $mon_rows++;
        break;
      case 'Дата экзамена':
        $qr_results['Дата экзамена'][] = $row;
        $tue_rows++;
        break;
      case 'Время экзамена':
        $qr_results['Время экзамена'][] = $row;
        $wed_rows++;
        break;
      case 'Аудитория':
        $qr_results['Аудитория'][] = $row;
        $thu_rows++;
        break;
      case 'Преподаватель':
        $qr_results['Преподаватель'][] = $row;
        $fri_rows++;
        break;
      default:
        break;
    }
    
}
$rows = max($mon_rows,$tue_rows,$thu_rows,$wed_rows,$fri_rows);
?>


<style type="text/style.css" media="all"> body { margin: 0; padding: 0;}  </style>
<table  align="center" border="1" cellpadding="1" cellspacing="1" height="200" width="650">
<thead>
<tr>
<th><b>Дисциплина</b></th>
<th><b>Дата экзамена</b></th>
<th><b>Время экзамена</b></th>
<th><b>Аудитория</b></th>
<th><b>Преподаватель</b></th>
</tr>
</thead>
<tbody>
<?php for($i=0;$i<$rows;$i++){ ?>
  <tr>
    <?php if(isset($qr_results['Дисциплина'][$i])){ ?> 
    <td> <?php echo $qr_results['Дисциплина'][$i]['discipline']; ?><br><?php echo $qr_results['Дисциплина'][$i]['discipline']; ?><br><?php echo $qr_results['Дисциплина'][$i]['discipline']; ?></td>
    <?php }else{ ?>
    <td> - </td>
    <?php } ?>
    <?php if(isset($qr_results['Дата экзамена'][$i])){ ?> 
    <td> <?php echo $qr_results['Дата экзамена'][$i]['exam date']; ?><br><?php echo $qr_results['Дата экзамена'][$i]['exam date']; ?><br><?php echo $qr_results['Дата экзамена'][$i]['exam date']; ?></td>
    <?php }else{ ?>
    <td> - </td>
    <?php } ?>
    <?php if(isset($qr_results['Время экзамена'][$i])){ ?> 
    <td> <?php echo $qr_results['Время экзамена'][$i]['subject']; ?><br><?php echo $qr_results['Время экзамена'][$i]['classroom']; ?><br><?php echo $qr_results['Время экзамена'][$i]['teacher']; ?></td>
    <?php }else{ ?>
    <td> - </td>
    <?php } ?>
    <?php if(isset($qr_results['Четверг'][$i])){ ?> 
    <td> <?php echo $qr_results['Четверг'][$i]['subject']; ?><br><?php echo $qr_results['Четверг'][$i]['classroom']; ?><br><?php echo $qr_results['Четверг'][$i]['teacher']; ?></td>
    <?php }else{ ?>
    <td> - </td>
    <?php } ?>
    <?php if(isset($qr_results['Пятница'][$i])){ ?> 
    <td> <?php echo $qr_results['Пятница'][$i]['subject']; ?><br><?php echo $qr_results['Пятница'][$i]['classroom']; ?><br><?php echo $qr_results['Пятница'][$i]['teacher']; ?></td>
    <?php }else{ ?>
    <td> - </td>
    <?php } ?>
  </tr>
<?php } ?>
</tbody>
</table>

Show only column headers. Does not display cells.
8275ec61cd5040d5b89b621b81655fb7.jpg
What is the problem? How to decide?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortop, 2017-05-16
@Fortop

The problem is that you most likely do not have data in the sample.
Solve, as usual, debugging.
Before the for loop, add var_dump($qr_results); and see what it outputs.
If the array is empty, then deal with getting the data.
If not empty, then with array structure and mass if

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question