Answer the question
In order to leave comments, you need to log in
Pull information from the database into a table on the site?
There is a table on the site with a couples schedule. There are 3 entries in each cell: Subject, audience, teacher.
It is necessary to display these three points about the pair from the database. How to implement it?
Answer the question
In order to leave comments, you need to log in
Incorrect question... It's not even known where you store the records, in separate tables or in one, but in different columns... But still, here is the code for working with the database and displaying it on the site, change the values for your own and add alignment in the cells tables.
<?php
// определяем начальные данные
$db_host = 'localhost';
$db_name = 'schedule';
$db_username = 'root';
$db_password = '';
$db_table_to_show = 'table';
// соединяемся с сервером базы данных
$connect_to_db = mysql_connect($db_host, $db_username, $db_password);
// подключаемся к базе данных
mysql_select_db($db_name, $connect_to_db);
$qr_result = mysql_query("select * from " . $db_table_to_show);
// выводим на страницу сайта заголовки HTML-таблицы
echo '<style type="text/css" media="all"> body { margin: 0; padding: 0;} </style>';
echo '<table border="1" cellspacing="0" cellpadding="0">';
echo '<thead>';
echo '<tr>';
echo '<th><b>День недели</b></th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
// выводим в HTML-таблицу данные из таблицы MySQL
while($data = mysql_fetch_array($qr_result)){
echo '<tr>';
echo '<td>' . $data['Предмет'] . '<br>' . $data['Аудитория'] . '<br>' . $data['Преподаватель'] . '</td>'; // вместо "Предмет", "Аудитория" и "Преподаватель" - наименования столбцов в таблице БД с твоими данными
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
// закрываем соединение с сервером базы данных
mysql_close($connect_to_db);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question