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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:40:01+00:00 2026-06-06T17:40:01+00:00

I’m trying to display comments on my site from my database. I know that

  • 0

I’m trying to display comments on my site from my database. I know that my connection is working, as shown by $test (which displays “Array”).

How do I convert the array into usable information? This is my best shot, but it doesn’t display anything:

<?php
$connect;

$sql_get_topic_info = "SELECT * FROM wall ORDER BY time ASC"; 
$res_get_comments_info = mysql_query($sql_get_comments_info); 
$num_get_comments_info = mysql_numrows($res_get_comments_info); 
$test = mysql_fetch_array(mysql_query($sql_get_topic_info)); //just to make sure the connection is working
echo $test; //displays "Array"


//Runs comment loop 
$i=0; 
while ($i < $num_get_comments_info) { 

$sel_comments_info_time = mysql_result($res_get_comments_info,$i,"time"); 
$sel_comments_info_message = mysql_result($res_get_comments_info,$i,"message"); 
$sel_comments_info_company = mysql_result($res_get_comments_info,$i,"company"); 

echo "<li>Company: $sel_comments_info_company<br/>"; 
echo "Comment: $sel_comments_info_message <br/>";
echo "$sel_comments_info_time"; 
echo "</li>"; 

$i++; 
} 
?>

Updated script: (from answer below)

$result = mysql_query("SELECT company, message FROM wall");

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("company: %s  message: %s", $row["company"], $row["message"]);
}

mysql_free_result($result);

which prints:

company: company 1 message: message 1company: company 2 message: message 2company: company 3 message: message 3
  • 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-06T17:40:03+00:00Added an answer on June 6, 2026 at 5:40 pm

    Usage of mysql_ is discouraged, you should be using mysqli_ functions instead.

    From mysql_fetch_array documentation:

    $result = mysql_query("SELECT id, name FROM mytable");
    
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        printf("ID: %s  Name: %s", $row[0], $row[1]);  
    }
    

    Use print_r($test) to see the array to see its format. Then you can use the loop above to display the parts of it in whatever order you want. Each column from your database is in the resulting row

    row = [col1, col2, col3...]
    

    You can access them using array indices $row[0], $row[1].... You can see the order by either looking at the order of columns in the database or seeing what it is in the print_r. Then you can just echo it out in the order you want.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a view passing on information from a database: def serve_article(request, id): served_article
I know there's a lot of other questions out there that deal with this

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.