这是我之前的一个跟进问题.我想写一个MYSQL语句,它回显每个以字母B开头的条目.
Function.php
function getCategory() {
$query = mysql_query("SELECT author FROM lyrics WHERE author [starts with letter B]") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) { ?>
<p><a href="##"><?= $row['author']; ?></a></p>
<?php }
Run Code Online (Sandbox Code Playgroud)
Category.php?类别= B
<?php include 'includes/header.php' ?>
<?php getCategory(); ?>
<?php include 'includes/footer.php' ?>
Run Code Online (Sandbox Code Playgroud)
就像我猜的那样.然后一个字母表中的每个字母,一个带有misc(数字等)
我使用php GET检查URL中的ID,然后从匹配该ID的数据库中检索tekst.这是执行该操作的代码片段:
function getLyric() {
$id = (int)$_GET['id'];
$query = mysql_query("SELECT * FROM lyrics WHERE id = ".$id."") or die(mysql_error());
if ($row = mysql_fetch_assoc($query)) { ?>
<h1><?= $row['title']; ?> lyrics</h1>
<h2><?= $row['author']; ?></h2>
<pre><?= $row['lyrics']; ?></pre>
<?php }
else { header("HTTP/1.1 404 Not Found"); header("Status 404 Not Found"); }
}
Run Code Online (Sandbox Code Playgroud)
这就是页面在我调用此函数的位置:
<?php include 'includes/header.php' ?>
<?php getLyric(); ?>
<?php include 'includes/footer.php' ?>
Run Code Online (Sandbox Code Playgroud)
不幸的是,函数中的404部分不起作用.我收到以下警告.Warning: Cannot modify header information - headers already sent by [redacted] functions.php on line 61.第61行是404部分; "else …