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

  • Home
  • SEARCH
  • 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 8176201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:04:27+00:00 2026-06-06T23:04:27+00:00

I was just quickly throwing together a script for an article website where I

  • 0

I was just quickly throwing together a script for an article website where I retrieve articles out of a database.

Here is my index.php script

    <?php
    // include header
    require("include/header.php");
    require("include/helperfunctions.inc.php");
    ?>

    <!-- page content -->
    <!-- left section -->
    <section id="contentleft">
<?php require("include/functions.php"); 
displayArticles();
foreach ($articles as $article) : ;
?>
<h2>Recent Articles</h2>
    <ul>
        <li><?php echo htmlout($articles['id']) ; ?></li>
        <li><?php echo htmlout($articles['title']) ; ?></li>
        <li><?php echo htmlout($articles['summary']) ; ?></li>
    </ul>
<?php endforeach; ?>
    </section>

    <!-- right content -->
    <section id="contentright">

    </section>

    <?php
    // include footer
    require("include/footer.php");
    ?>

Here is the start of the function library

    function displayArticles($order="publicationdate DESC"){
        // connect to the database
        include("include/db.inc.php");
    $query = "SELECT id, title, summary FROM maths order by ". $order . " limit 10";

// query the database
$result = mysqli_query($link, $query);
    // error checking
    if(mysqli_connect_errno()){
    // $error = "error fetching articles";
    echo " could not connect: " . mysqli_connect_errno() . " ";
    exit();     
}
// loop through storing values into array
while($row = mysqli_fetch_array($result)){
    $articles[] = array('id'=>$row['id'] , 'title'=>$row['title'],'summary'=>$row['summary']);        
}

    }

    ?>

I get this error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\Apache24\htdocs\include\functions.php on line 17 Recent Articles Notice: Undefined variable: articles in C:\Apache24\htdocs\home.php on line 14 Warning: Invalid argument supplied for foreach() in C:\Apache24\htdocs\home.php on line 14

  • 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-06T23:04:29+00:00Added an answer on June 6, 2026 at 11:04 pm

    It looks like a scope issue with the $articles object. You create $articles in the displayArticles() function.. but outside of the function, your other code does not know about it. Try returning $articles inside displayArticles(), and replace your displayArticles(); call at the top of the first page with:

    $articles = displayArticles();
    

    Also, as panique in the comments pointed out, you are referencing the wrong object inside your foreach block. Remove the ‘s’ at the end of each $articles[blah], so that it reads $article[blah].

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

Sidebar

Related Questions

I'm just trying to quickly debug a webservice by printing out the contents of
I just want to quickly store an array which I get from a remote
I'm just wondering exactly what factors affect how quickly createthread executes, and how long
I'm just getting the hang of Rails console, and finding it useful for quickly
Say I have a table People , is there a way to just quickly
It just happened to me that I commented out a line of code for
I was trying to just quickly integrate the Windows Media Player via COM to
Sorry for turning to here for such a basic question, but can someone just
Just have a quickly question (more of a curiosity thing) based on a problem
I just want to quickly see the properties and values of an object in

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.