本文介绍了通过类别中的多篇文章获取文章类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 所以我想在文章类别中展示我的文章,它会像 类别1 ...... ............ artikel1.1 artikel1.2 artikel1.3 更多按钮 categori 2 ........... ....... artikel2.1 artikel2.2 artikel2.3 更多按钮 但是在我尝试之后,它只显示每个类别的第一篇文章 类别1 ............... artikel1.1 more按钮 类别2 ............... artikel2.1 更多按钮 这是我的查询So i want to show my article within the article category, it will likecategory 1.................. artikel1.1 artikel1.2 artikel1.3 more buttoncategori 2.................. artikel2.1 artikel2.2 artikel2.3 more buttonbut after i tried it, it show only the first article for each categorycategory 1............... artikel1.1 more buttoncategory 2............... artikel2.1 more buttonhere is my query$sql_kategori_berita = "SELECT k.id,k.name,count(ar.id) as countartikel,";$sql_kategori_berita .="ar.id as arid,ar.judul,ar.content, ar.kategori, ar.tanggal";$sql_kategori_berita .=" FROM " .kategori_artikel::$nama_tabel. " k";$sql_kategori_berita .=" LEFT JOIN " .artikel::$nama_tabel. " ar";$sql_kategori_berita .=" ON k.id = ar.kategori";$sql_kategori_berita .=" WHERE k.id NOT IN (1)";$sql_kategori_berita .=" GROUP BY k.id";$database->query($sql_kategori_berita);$database->execute();$nResults = $database->rowCount();if($nResults > 0){ $i2 = 0; while($row = $database->fetch()){ if($i2 % 3 == 0 || $i2 == 0){ echo "<div class=\"row\">"; } $output ="<div class=\"col-md-4 col-sm-6 latest-news\">"; $output .="<h3 style=\"border-bottom: 2px solid #53555c;line-height: 1.5em;margin: 30px 0;\">{$row['name']}</h3>"; if($row['countartikel'] > 0){ $i = 0; if($i <= 2){ $output .="<div class=\"row\">"; $output .="<div class=\"col-sm-12\">"; $output .="<div class=\"caption\"><a href=\"detail_artikel.php?i={$row['arid']}\"><b>{$row['judul']}</b></a></div>"; $phpdate = strtotime( $row['tanggal'] ); $mysqldate = date( 'F j, Y, g:i a ', $phpdate ); $output .="<div class=\"date\" style=\"font-size: 14px;\">{$mysqldate}</div>"; $content = html_entity_decode($row['content']); $content = strip_tags($content); $x = $content; if(strlen($x)<=100) $y = $x; else $y=substr($x,0,100) . '...'; $output .="<div class=\"intro\">{$y}</div>"; $output .="</div>"; $output .="</div>"; } $i++; echo $i; if($row['countartikel'] > 3){ $output .="<div class=\"row\">"; $output .="<div class=\"col-sm-12\">"; $output .="<a href=\"list_artikel.php?i={$row['id']}\" class=\"btn\"><b>Selengkapnya »</b></a>"; $output .="</div>"; $output .="</div>"; } }else{ $output .="<div class=\"row\">"; $output .="<div class=\"col-sm-12\">"; $output .="<div class=\"caption\"><b>Belum terdapat artikel...</b></div>"; $output .="</div>"; $output .="</div>"; } $output .="</div>"; echo $output; $i2++; if($i2 % 3 == 0 || $i2 == $nResults){ echo "</div> <hr/>"; } }} 我的代码出了什么问题?so what is wrong with my code?推荐答案 sql_kategori_berita = SELECT k.id,k .name,count(ar.id)as countartikel,;sql_kategori_berita = "SELECT k.id,k.name,count(ar.id) as countartikel,"; sql_kategori_berita 。= ar.id as arid,ar.judul,ar.content,ar.kategori,ar.tanggal;sql_kategori_berita .="ar.id as arid,ar.judul,ar.content, ar.kategori, ar.tanggal"; sql_kategori_berita 。= FROM .kategori_artikel ::sql_kategori_berita .=" FROM " .kategori_artikel:: 这篇关于通过类别中的多篇文章获取文章类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 08:54