Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:33:25+00:00 2026-06-08T03:33:25+00:00

I want to fetch data from my MySQL and echo it out only if

  • 0

I want to fetch data from my MySQL and echo it out only if $featured == 1.
It works, the only one with $featured == 1 will show title, but my problem is that it also makes posts from everything else in my database (empty posts). I only want it to show the posts with == 1 and nothing more nothing less. I can’t manage to fix it.

<aside id="featured" class="body"><article> 
<?php
for ($i=0; $i <$num_results; $i++){
$row1 = $result1->fetch_assoc();
$featured = ($row1['featured']);
if ($featured == 1) {
echo $row1['title'];    
} else {
}
?>
<figure> 
<img src="images/black2.gif" alt="Black 2" style="width: 300px;"/> 
</figure>   
<hgroup>    
<h2>Featured Article</h2> 
<h3><a href="goodies/black2.html">
</a></h3> 
</hgroup>   
<p> </p> 
<footer class="post-info"> 
<abbr class="published" title="date">20 juli 2012</abbr>    
<address class="vcard author">By<a class="url fn" href="portfolio.html">F4LLCON</a> 
</address></footer><!-- /.post-info -->
</article>
<?php
}
$result1->free();   
?>

</aside><!-- /#featured -->

  • Will look like:

enter image description here


  • But I want it like this:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:33:27+00:00Added an answer on June 8, 2026 at 3:33 am

    Your for body contains printing large amount of HTML regardless of featured checking, that is, outside your if.

    You probably should move two lines

    } else { 
    }
    

    line to the bottom of the code snippet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want write a simple query which will fetch data from a table (which
In asp.net(C#) i want to fetch data from a database using a stored procedure
I want to fetch the title from book table and the subject name from
I want to be able to separate the birthday from the mysql data into
I am trying to show the data coming from mysql database as a table
Hi I have been using this code to fetch data from mysql database and
So, if I want to pull some data from my database (PHP, MySql), whether
I want to load data from a MySQL database to a PHP page using
I am populating a drop down menu from mysql database. It works well, But
I am trying to return all selected data from mysql table. What I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.