Php 使用foreach创建HTML表
我正在尝试用数据库中的结果构建表Php 使用foreach创建HTML表,php,Php,我正在尝试用数据库中的结果构建表 global $wpdb; $results = $wpdb->get_results( 'SELECT * FROM wp_prijavljeniupis ',OBJECT); 然后我试着用这种方法做桌子 echo '<table>'; echo '<thead>'; echo '<tr>'; echo '<th>UID<th>'; echo '<th&
global $wpdb;
$results = $wpdb->get_results( 'SELECT * FROM wp_prijavljeniupis ',OBJECT);
然后我试着用这种方法做桌子
echo '<table>';
echo '<thead>';
echo '<tr>';
echo '<th>UID<th>';
echo '<th>ID<th>';
echo '<th>Ime<th>';
echo '<th>Prezime<th>';
echo '<th>JMBG<th>';
echo '<th>Telefon<th>';
echo '<th>Adresa<th>';
echo '<th>BrojUlice<th>';
echo '<th>PttBroj<th>';
echo '<th>Grad<th>';
echo '<th>Drzava<th>';
echo '<th>Grad<th>';
echo '<th>Odsek<th>';
echo '<th>NacinPlacanja<th>';
echo '<th>NacinSkolovanja<th>';
echo '<th>kampanja<th>';
echo '</tr>';
echo '<thead>';
echo '<tbody>';
foreach ( $results as $result )
{
echo '<td>'.$result->UID.'</td>';
echo '<td>'.$result->ID.'</td>';
echo '<td>'.$result->Ime.'</td>';
echo '<td>'.$result->Prezime.'</td>';
echo '<td>'.$result->JMBG.'</td>';
echo '<td>'.$result->Telefon.'</td>';
echo '<td>'.$result->Adresa.'</td>';
echo '<td>'.$result->BrojUlice.'</td>';
echo '<td>'.$result->PttBroj.'</td>';
echo '<td>'.$result->Grad.'</td>';
echo '<td>'.$result->Drzava.'</td>';
echo '<td>'.$result->Odsek.'</td>';
echo '<td>'.$result->NacinPlacanja.'</td>';
echo '<td>'.$result->NacinSkolovanja.'</td>';
echo '<td>'.$result->Kampanja.'</td>';
}
echo '<tbody>';
echo '</table>';
我不知道如何在我的tbody部分实现tr,因为我有循环,我尝试了不同的选项,但没有成功您在循环开始和结束时忘记了
echo '<table>';
echo '<thead>';
echo '<tr>';
echo '<th>UID<th>';
echo '<th>ID<th>';
echo '<th>Ime<th>';
echo '<th>Prezime<th>';
echo '<th>JMBG<th>';
echo '<th>Telefon<th>';
echo '<th>Adresa<th>';
echo '<th>BrojUlice<th>';
echo '<th>PttBroj<th>';
echo '<th>Grad<th>';
echo '<th>Drzava<th>';
echo '<th>Grad<th>';
echo '<th>Odsek<th>';
echo '<th>NacinPlacanja<th>';
echo '<th>NacinSkolovanja<th>';
echo '<th>kampanja<th>';
echo '</tr>';
echo '<thead>';
echo '<tbody>';
foreach ( $results as $result )
{
echo '<tr>';
echo '<td>'.$result->UID.'</td>';
echo '<td>'.$result->ID.'</td>';
echo '<td>'.$result->Ime.'</td>';
echo '<td>'.$result->Prezime.'</td>';
echo '<td>'.$result->JMBG.'</td>';
echo '<td>'.$result->Telefon.'</td>';
echo '<td>'.$result->Adresa.'</td>';
echo '<td>'.$result->BrojUlice.'</td>';
echo '<td>'.$result->PttBroj.'</td>';
echo '<td>'.$result->Grad.'</td>';
echo '<td>'.$result->Drzava.'</td>';
echo '<td>'.$result->Odsek.'</td>';
echo '<td>'.$result->NacinPlacanja.'</td>';
echo '<td>'.$result->NacinSkolovanja.'</td>';
echo '<td>'.$result->Kampanja.'</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
您在表头添加了额外的列 回声“梯度”; 表头标签和表体标签的列数应该相等,这样只有您的表才能很好地对齐 试试这个代码
echo '<thead>';
echo '<tr>';
echo '<th>UID</th>';
echo '<th>ID</th>';
echo '<th>Ime</th>';
echo '<th>Prezime</th>';
echo '<th>JMBG</th>';
echo '<th>Telefon</th>';
echo '<th>Adresa</th>';
echo '<th>BrojUlice</th>';
echo '<th>PttBroj</th>';
echo '<th>Grad</th>';
echo '<th>Drzava</th>';
echo '<th>Odsek</th>';
echo '<th>NacinPlacanja</th>';
echo '<th>NacinSkolovanja</th>';
echo '<th>kampanja</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ( $results as $result )
{
echo "<tr>";
echo '<td>'.$result->UID.'</td>';
echo '<td>'.$result->ID.'</td>';
echo '<td>'.$result->Ime.'</td>';
echo '<td>'.$result->Prezime.'</td>';
echo '<td>'.$result->JMBG.'</td>';
echo '<td>'.$result->Telefon.'</td>';
echo '<td>'.$result->Adresa.'</td>';
echo '<td>'.$result->BrojUlice.'</td>';
echo '<td>'.$result->PttBroj.'</td>';
echo '<td>'.$result->Grad.'</td>';
echo '<td>'.$result->Drzava.'</td>';
echo '<td>'.$result->Odsek.'</td>';
echo '<td>'.$result->NacinPlacanja.'</td>';
echo '<td>'.$result->NacinSkolovanja.'</td>';
echo '<td>'.$result->Kampanja.'</td>';
echo "</tr>"
}
echo '</tbody>';
echo '</table>';
你有回声;这是回声@回答的人弗拉基米尔·什图斯犯了一些语法错误,我纠正了它们。其中一个是echo,应该是echo;-重新加载答案/代码,然后再试一次。@Fred-ii我告诉过你错误不在sintax中,我已经试过了,我写过我不确定如何实现tr,请删除question@VladimirŠtus我不是回答的人。请看下面的名字。。。。几分钟前。@VladimirŠtus你会看到什么,得到什么?你能发布截图吗?