如何使用 php 中的按钮删除 LIMIT?
How do i remove the LIMIT with a button in php?
现在我想制作一个按钮,从我的 php 代码中删除 (LIMIT 3),这样所有的行都会显示,而不是限制在 3
$query = "SELECT * FROM artikler ORDER BY 1 DESC LIMIT 3";
$result = $mysqli->query($query);
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
$titel = $row['art_titel'];
$indhold = $row['art_indhold'];
echo "<article class='article-box'>";
echo "<div class='art-title'>$titel</div>";
echo "<div class='art-content'>$indhold</div>";
echo "<div class='art-view'><a href='pages/e-artikel.php?id=$row[art_id]'>Vis</a></div>";
echo "<div class='art-date'>".date_format(date_create($row["art_dato"]),'d/m/Y')."</div>";
echo "</article>";
}
我一直在考虑制作一个 IF ELSE 语句,但我不太确定我该怎么做,请详细解释我对 php 很陌生。
JS代码:
<script>
function getRecords(type){
location.href= 'action.php?limited='+type;
}
</script>
HTML代码:
<input type='button' onclick="getRecords('all')" id='submit_button' name='showall' value='Show All'/>
<input type='button' onclick="getRecords('limited')" id='submit_button' name='showlimited' value='Show Top 3'/>
PHP代码:
$limited = $_GET['limited'];//As per code change it to GET
$condition = '';
if($limited == 'limited'){
$condition = ' LIMIT 3';
}
$query = "SELECT * FROM artikler ORDER BY 1 DESC $condition";
添加一个HTML提交按钮:
<form method="post">
<input type="submit" value="showAll" name="showAll" />
</form>
在PHP中获取按钮按下的代码 if/else
:
if(isset($_POST['showAll'])){
$query = "SELECT * FROM artikler ORDER BY 1 DESC";
}else{
$query = "SELECT * FROM artikler ORDER BY 1 DESC LIMIT 3";
}
$result = $mysqli->query($query);
// rest of the code...
现在我想制作一个按钮,从我的 php 代码中删除 (LIMIT 3),这样所有的行都会显示,而不是限制在 3
$query = "SELECT * FROM artikler ORDER BY 1 DESC LIMIT 3";
$result = $mysqli->query($query);
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
$titel = $row['art_titel'];
$indhold = $row['art_indhold'];
echo "<article class='article-box'>";
echo "<div class='art-title'>$titel</div>";
echo "<div class='art-content'>$indhold</div>";
echo "<div class='art-view'><a href='pages/e-artikel.php?id=$row[art_id]'>Vis</a></div>";
echo "<div class='art-date'>".date_format(date_create($row["art_dato"]),'d/m/Y')."</div>";
echo "</article>";
}
我一直在考虑制作一个 IF ELSE 语句,但我不太确定我该怎么做,请详细解释我对 php 很陌生。
JS代码:
<script>
function getRecords(type){
location.href= 'action.php?limited='+type;
}
</script>
HTML代码:
<input type='button' onclick="getRecords('all')" id='submit_button' name='showall' value='Show All'/>
<input type='button' onclick="getRecords('limited')" id='submit_button' name='showlimited' value='Show Top 3'/>
PHP代码:
$limited = $_GET['limited'];//As per code change it to GET
$condition = '';
if($limited == 'limited'){
$condition = ' LIMIT 3';
}
$query = "SELECT * FROM artikler ORDER BY 1 DESC $condition";
添加一个HTML提交按钮:
<form method="post">
<input type="submit" value="showAll" name="showAll" />
</form>
在PHP中获取按钮按下的代码 if/else
:
if(isset($_POST['showAll'])){
$query = "SELECT * FROM artikler ORDER BY 1 DESC";
}else{
$query = "SELECT * FROM artikler ORDER BY 1 DESC LIMIT 3";
}
$result = $mysqli->query($query);
// rest of the code...