Php Database Output Not Showing The Correct Way
Solution 1:
First of all: Since you want to fetch multiple topics from the DB, you must remove the LIMIT 1
from the query and the if($j >= 1) continue;
in the foreach loop, as they both are restricting your output to only 1 topic.
In your foreach loop for $toppics
(correct spelling: topics ;P) you currently only echo an anchor tag (link), but what you want is (to use your words here) a 'block'. Whatever you want that block to look like, the place for defining that is within that foreach loop.
Now I don't know what elements, classes or stylings you use / want to use, so I will make an example of a block that consists of a title and below that the link:
//rename $topic keys to the names of your DB columnsforeach($toppicsas$topic){
echo'<div>';
echo'<h3>'.$topic['title'].'</h3><br>';
echo'<a href="#section'.$topic['id'].'">'.$topic['link_text'].'</a>';
echo'</div><br>';
}
I know my solution will not look exactly like your given image, but it should get the point across how and where you can build your blocks.
I think this problem should have been easily solveable when you know the basics of HTML, so I would really recommend you learning a bit more about HTML before you work on big projects.
Edit after question was edited:
As I mentioned in my answer, my solution will not look exactly like your given image
because I don't know what elements, classes or stylings you use
. Your remaining problem is now the usage of the correct html tags, classes and stylings.
It appears that the parent element of the generated divs is styled the way you want the single blocks to look like. So what you could do is remove the parent element and use it as a replacement of the generated div, like so:
<divclass="col-md-6"><divclass="well dash-box"><h2><spanclass="glyphicon glyphicon-list-alt"aria-hidden="true"></span> Stel jezelf voor</h2><h5><ahref="https://tom.lbmedia.nl/onderwerp"> Laat wetn wie jij en je business zijn</a></h5></div></div><divclass="col-md-6"><!--<div class="well dash-box">--><h2><spanclass="glyphicon glyphicon-list-alt"aria-hidden="true"></span> 12</h2><?php$toppics = $app->get_topics();
$i = 0;
foreach($toppicsas$topic){
echo'<div class="well dash-box">';
echo'<h3>'.$topic['onderwerp'].'</h3><br>';
echo'<a href="#section' . $i++ . '">' .$topic['omschrijving'].'</a>';
echo'</div><br>';
}
?><!--</div>--></div>
sidenote: I do not agree with your building of your href attribute #section1. When building these sections you would have to know that exact index from that previous foreach-loop. Instead, use some attribute from the topic itself, maybe its ID, title, or description (like I did in the first codeblock). This way when you are building the sections you can easily know how to set the elements id attribute.
Post a Comment for "Php Database Output Not Showing The Correct Way"