-1

Okay so imagine you have 10 articles each of these articles have a category now you want the articles to sorted under the category and you want 4 articles from each category here is how i wanna do this i want it to pull all of the category names and id's out of tblcategory then put those into variables then to run another prepared statement to then use the categories that it fetched to then find the associated articles so then itll look like this

Crypto:
Article1
Article2
Article3
Article4

e-sports:
Article1
Article2
Article3
Article4

Here is what the currently code I have

$stmt = mysqli_prepare($con, "select name, id from tblcategory ");
$stmt->execute();
$stmt->bind_result($catname, $catid);
while ($stmt->fetch()){
?>
<?php
$catname
?>
<?php 
$stmt = mysqli_prepare($con, "select tblposts.PostTitle, tblposts.year, tblposts.month, tblposts.PostTitle,tblposts.PostImage,tblcategory.CategoryName,tblcategory.id, tblwritter.Writter,tblposts.PostDetails,tblposts.PostingDate,tblposts.PostUrl from tblposts left join tblcategory on tblcategory.id=tblposts.CategoryId left join tblwritter on tblwritter.WritterId=tblposts.WritterId where tblposts.Is_Active=? AND tblcategory.id=? order by tblposts.id ");
$stmt->bind_param('ii', $active,$catid);
$stmt->execute();
$stmt->bind_result($pid,$year,$month,$posttitle,$PostImage,$category,$cid,$writter,$postdetails,$postingdate,$url);
while ($stmt->fetch()){
?>
<?php 
$article

}
New contributor
Neiko101 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Neiko101 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.