您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 第1行“ FROM nyheder ORDER BY ID DESC LIMIT 2”附近
找到了我不知道为什么不起作用的地方 nyheder(意思是新闻)
<div class="container">
<h2>Nyheder</h2>
<div class="row">
<?php
$html = '';
$page = '';
$id = '';
$news_pr_page = 5;
$current_page = 1;
if (isset($_GET['pagenr']) && is_int($_GET['pagenr'] * 1)){
$page = $_GET['pagenr'];
$current_page = ($_GET['pagenr'] * 1);
}
$sql ="SELECT COUNT(ID) AS antal FROM nyheder";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$products = $row['antal'];
//exit($products);
//echo ($prody);
// $total_pages = ceil($products / $news_pr_page);
//exit($total_pages);
$offset = ($current_page - 1) * $news_pr_page;
$sql = "SELECT * FROM nyheder
ORDER BY ID ASC LIMIT $news_pr_page OFFSET $offset";
$arr = getData($sql, $conn);
foreach($arr as $value){
$html .= '
<div class="col-lg-8">
<div class="mt-4 nyheder white">
<div class="card-body">
<h3 class="card-title">'.$value['overskrift'].'</h3>
<p>'.$value['oprettelsesdato'].'</p>
<p>'. substr($value['tekst'], 0, 182) . '...</p>
<a href="?page=nyhedSingle&id=' . $value['ID'] . '"><button>Læs mere</button></a>
</div>
</div>
</div>
';
}
$html .= '</ul>
</div>
</div>';
$html .='<ul class="pagination">';
if($page > 1 && $page !== 1)
{
$href = '?page=nyheder&id='.$id.'&pagenr='.($current_page > 1 ? $current_page-1 : 1).'';
$html .= '<li><a href="'.$href.'">Tidligere nyheder</a></li>';
}
if($products >= $news_pr_page)
{
$href = '?page=nyheder&id='.$id.'&pagenr='.($current_page+1).'';
$html .= '<li><a href="'.$href.'">Ældre nyheder</a></li>';
}
return $html;
?>
也发现了这一点,希望这种帮助我不习惯stackoverflow我该如何更好地解释我的英语,不好意思
<a href="../?page=nyheder">Tilbage</a>
<?php
$id = $_GET['id'];
$html = '';
//Min SQL-sætning til hentning af data
$sql = "SELECT * FROM nyheder
WHERE nyheder.ID = " . $id . "
ORDER BY ID ASC LIMIT 1";
$arr = getData($sql, $conn);
if(is_array($arr)){
foreach($arr as $value){
$html .= '
<div class="col-lg-8">
<div class="mt-4 nyhederSingle white">
<div class="card-body">
<h3 class="card-title">'.$value['overskrift'].'</h3>
<p>'.$value['oprettelsesdato'].'</p>
<p>'.$value['tekst'].'</p>
</div>
</div>
</div>
';
}
}
return $html;
?>
答案 0 :(得分:0)
很抱歉发现所有问题
$ sql =“选择nyheder。*从nyheder按ID DESC LIMIT 2排序。”
它在第67行。
<?php
$sql = " SELECT * FROM omklubben ";
$arr = getData($sql, $conn);
foreach($arr as $value){
$html = '
<div class="container">
<div class="row">
<div class="col-lg-8">
<div class="mt-4 omKlubben white">
<div class="card-body">
<h3 class="card-title">'. $value['headline'] .'</h3>
<p>'. $value['text'] .'</p>
</div>
</div>
<div class="mt-4 white">
<div class="card-body brugteKajakkerForside">
<h3 class="card-title" style="color:black;">Brugte kajakker</h3>
<div class="row">';
}
$sql = "
SELECT kajakker.model, kajakker.pris,
kajak_billede.billednavn
FROM kajakker
INNER JOIN kajak_billede
ON kajak_billede.fk_kajak = kajakker.ID
ORDER BY ID DESC LIMIT 3";
$arr = getData($sql, $conn);
foreach($arr as $value){
$html .= '
<div class="col-md-4">
<img src="images/' . $value['billednavn'] . '" alt="' . $value['billednavn'] . '">
<div class="col-md-12">
<div class="priser" style="width:100%; background-color:#95cce8;">
<p>'. $value['model'] .'</p>
<p>'. $value['pris'] .' kr.</p>
</div>
</div>
</div>
';
}
$html .= '
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="nyhederForside col-md-12">
<form action="" method="get">
<center>
<input type="hidden" name="page" value="soegning">
<input type="search" name="fritekst" placeholder="Søg">
</center>
</form>
</div>
<div class="list-group">
<div class="nyhederForside white col-md-12">
<img src="../images/img02.jpg" style="width:100%" alt="">
<h3>Nyheder</h3>';
$sql = "SELECT nyheder * FROM nyheder ORDER BY ID DESC LIMIT 2";
$arr = getData($sql, $conn);
foreach($arr as $value){
$html .= '<p>' . showDateSmall($value['oprettelsesdato']) . ' ' . $value['overskrift'] . '</p>';
}
$html .= '
<center><a href="?page=nyheder"><button style="cursor:pointer;">Nyheder >></button></a></center>
</div>
<div class="nyhederForside white col-md-12" style="margin-top:30px;">
<img src="../images/img01.jpg" style="width:100%" alt="">
<h3>2018</h3>
<p>Marts</p>';
$sql = "SELECT bgv_info.* FROM bgv_info ORDER BY ID DESC LIMIT 2";
$arr = getData($sql, $conn);
foreach($arr as $value){
$html .= '<p>' . showDateSmall($value['oprettelsesdato']) . ' ' . $value['bgv_navn'] . '</p>';
}
$html .= '
<center><a href="?page=arrangementer"><button style="cursor:pointer;">Kalender >></button></a></center>
</div>
</div>
</div>
</div>
</div>';
return $html;
?>