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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:08:09+00:00 2026-05-26T19:08:09+00:00

This is my code: <?php mysql_connect(localhost,*****,********) or die(Can’t connect to DB); mysql_select_db(kroltan_main) or die(Can’t

  • 0

This is my code:

<?php 
mysql_connect("localhost","*****","********") or die("Can't connect to DB");
mysql_select_db("kroltan_main") or die("Can't select to DB");
$result = mysql_query("SELECT * FROM comments") or die("Can't fetch data");
if(mysql_num_rows($result) > 0){
    $info = mysql_fetch_assoc($result);
    while($row = mysql_fetch_assoc($result)){
        echo "<div class='t_post'>";
        echo "<div class='t_message'>" .$row["comment"]. "</div>";
        echo "<div class='t_info'>" .$row["name"]. "</div>";
        echo "</div>";
    }
}
?>

I’m trying to generate a container div with two divs inside, one that shows the “name” value of a MySQL row, and the other that shows the “comment” value. But when i test it, there are no contents (nothing is echoed). My MySQL table has contents on it, so it’s a problem with my code. http://kroltan.eliti.com.br/?/=Talk. The page has some info on it, but that’s irrelevant.

  • 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-05-26T19:08:09+00:00Added an answer on May 26, 2026 at 7:08 pm

    I’ve tidied up the code and the following should work OK:

    <?php 
    mysql_connect("localhost","*****","********") or die("Can't connect to DB");
    mysql_select_db("kroltan_main") or die("Can't select to DB");
    $result = mysql_query("SELECT name,comment FROM comments") or die("Can't fetch data");
    
    while($row = mysql_fetch_assoc($result)){
    ?>
    <div class="t_post">
        <div class="t_message"><?php echo $row["comment"] ?></div>
        <div class="t_info"><?php echo $row["name"] ?></div>
    </div>
    <?php
    }
    ?>
    

    Changes I’ve made are:

    • superfluous $info = mysql_fetch_assoc() removed
    • used inline echo() calls to make the markup more readable
    • only returning the columns you need from the query instead of SELECT *
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of PHP code: <?php $username=$_POST['username']; $password=$_POST['password']; if($username&&$password){ $connect=mysql_connect(localhost,root,) or die(
I have this code in PHP $max=SELECT MAX(num) FROM info; $maxquery= mysql_query($max) or die
Consider the following code: <?php $conn = mysql_connect('localhost', 'username', 'password'); mysql_select_db('database', $conn); ?> This
The code: <?php $local_id = $_GET['id']; mysql_connect(localhost, root, ) or die(Could not connect: .
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT
I just saw this code while studying the wordpress source code (PHP), You can
I am using MySQL and PHP 5.3 and tried this code. $dbhost = 'localhost';
I got this code from this site: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx But I'm just a beginner so
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I have this code in PHP. It connects to the DB fine, but pops

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.