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 7930895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:33:41+00:00 2026-06-03T20:33:41+00:00

I have a function loadContent() that when called, queries a database, formats the data

  • 0

I have a function loadContent() that when called, queries a database, formats the data and should return the result. This is being used to build a very primitive CMS and this function is used to load the articles from the database.

Here is the function is question:

    $articles = mysql_query("SELECT `id`, `name`, `content`, `keywords`, `description`, `access_level` FROM `tb_articles` WHERE `page_id`='$pageID'");
            if(!$articles){
                die('Error!: ' . mysql_error());
            }
            while($arts = mysql_fetch_assoc($articles)){
                $content .= '<div class="article" id="art-' . $arts['id'] . '">';
                $content .= '<h1>' . $arts['name'] . '</h1>';
                $content .= $arts['content'];
                $content .= '</div>';
            }
        return $content; 
    }else{

My problem is that nothing is being returned. The SQL is verified, it should return two rows. I have commented out everything in the loop and added the line $content .= 'test'; and changed the return statement to echo $content; and the function successfully echo’ed “test” twice. So whats wrong with what I have done?

Thanks for helping me out, I’m pretty new to PHP.

UPDATE:

The post now represents all valid changes.

I got somewhere with var_dump. I dumped $content just before the return statement. All of the articles in the database (2 of them) were displayed inside of string(2445) "". This confirms there are no problems with the query. I am now thinking it has something to do with the return statement.

  • 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-03T20:33:43+00:00Added an answer on June 3, 2026 at 8:33 pm

    Try updating your code to this:

    function loadContent(){
       $content = '';
       $pageID = 1;
       //
       $articles = mysql_query("SELECT `id`, `name`, `content`, `keywords`, `description`, `access_level` 
                                FROM `tb_articles` 
                                WHERE `page_id`='$pageID'");
    
            // you only need the associative array
            while($arts = mysql_fetch_array($articles, MYSQL_ASSOC)){
                // close your tag properly and use the concat operator
                $content .= '<div class="article" id="art-' . $arts['id'] . '">';
                $content .= '<h1>' . $arts['name'] . '</h1>';
                $content .= $arts['content'];
                $content .= '</div>';
            }
    
        return $content;
    
     }
    

    Also you could try running mysql_error() after your call to mysql_query() to see if anything goes wrong.

    Another thing that you should check is so that there actually is a row with page_id equal to 1 in your database. You should also make sure that your column names are correct.

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

Sidebar

Related Questions

So I have function that formats a date to coerce to given enum DateType{CURRENT,
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function getCartItems in cart.js and I want to call that function in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
basically I have a function that resizes elements accordingly with jquery triggering the function
I have this code: $(document).ready(function(){ $(.links a).click(function(e){ var toLoad = products.html # + this.id;
The wierdest thing. I have a function which calls: var clicked_el = event.target.id; This
I have a PageBase page in App_Code. In it is a function called LoadContext().
I allready have this: $(document).ready(function() { // one time stuff $.ajaxSetup({ cache:false }); }

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.