我不是一个后端开发人员,而是一个前端开发人员,但是我正在尝试创建一个简单的php搜索,我已经遵循了这里的教程,并对它的不推荐位进行了更改。我有一个包含子行和子列的数据库,我正在尝试从中获取一些数据:
首先,我创建了html
<form action="search.php" method="GET">
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
然后是php位:
$con = mysqli_connect("localhost", "USER", "PSW", "DBNAME") or die("Error connecting to database: ".mysqli_error());
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysqli_real_escape_string($con, $query);
$raw_results = mysqli_query($con, "SELECT * FROM article
WHERE (`title` LIKE '%".$query."%') ") or die(mysqli_error($con));
if(mysqli_num_rows($raw_results) > 0){
while($results = mysqli_fetch_array($raw_results, MYSQLI_ASSOC)){
echo "<p><h3>".$results['page_id']."</h3>".$results['title']."</p><p>".$results['space']."</p>";
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
上面是罚款,它给我的文章标题和文章id我在我的数据库。但我需要得到 space
以及 year
. 附db结构:
以及
通过四处阅读并查看我的后端开发人员当时所做的工作,我可以在其他地方看到这一行,如果它有帮助的话,应该会走上正确的轨道。
$query = "SELECT A.id AS article_id, A.title AS title, C.name as space, A.page_id, T.year, T.month, T.id as time_id FROM article AS A INNER JOIN space AS S ON S.article_id = A.id INNER JOIN country AS C ON C.id = S.country_id INNER JOIN time AS T ON A.id = T.article_id WHERE (T.year BETWEEN ".$year_start." AND ".$year_stop.") GROUP BY A.title, C.name";
1条答案
按热度按时间qv7cva1a1#
代替
用这个
此查询将帮助您显示php中所需的列。