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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:40:37+00:00 2026-05-13T06:40:37+00:00

<html> <head> <title>Test</title> <link rel=stylesheet type=text/css href=style.css> </head> <body> <?php $username =matt; $pass =

  • 0
<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css"> 
</head>
<body>
    <?php 
       $username ="matt";
       $pass = "bs12kfj";
       $db = "mytest";
       $tbl = "test2";
       mysql_connect(localhost,$username,$pass);
       mysql_select_db($db) or die( "Unable to select database");
       $res = mysql_query("SELECT * FROM test2;");
       $num = mysql_numrows($res);
       echo "<table border='2'><tr>The Peeps</tr>"; 
       while ($r = mysql_fetch_array($res)) {
         echo "<tr>";
         foreach($r as $rs){
                     echo "<td>$rs</td>";
                     }
         echo "</tr>";
       }
       ?>

</body>

This code executes without error but the output contains a duplicate of every column of every row like so.

<table border='2'><tr>The Peeps</tr>
<tr><td>"matt"</td><td>"matt"</td><td>"phillips"</td><td>"phillips></td><td>"mathew.p@waburg.com"</td><td>"mathew.p@waburg.com"</td><td>20</td><td>20</td></tr><tr><td>"paul"</td><td>"paul"</td><td>"franklin"</td><td>"franklin"</td><td>"dude@live.com"</td><td>"dude@live.com"</td><td>30</td><td>30</td></tr><tr><td>"steve"</td><td>"steve"</td><td>"jobs"</td><td>"jobs"</td><td>"sjobs@apple.com"</td><td>"sjobs@apple.com"</td><td>23</td><td>23</td>

I don’t understand why each column is duplicated when there is only a single <td></td> tag in the echo statement.
I also checked the db and the table does not contain duplicate entries.

  • 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-13T06:40:38+00:00Added an answer on May 13, 2026 at 6:40 am

    You are probably fetching your MySQL result array in the default mode of MYSQL_BOTH.

    Try this:

    while ($r = mysql_fetch_array($res,MYSQL_ASSOC)) {
                 echo "<tr>";
         foreach($r as $rs){
                     echo "<td>$rs</td>";
                     }
                 echo "</tr>";
           }
    

    If you don’t specify the second argument to mysql_fetch_array(), then MYSQL_BOTH is used, and you end up with both an associative array index of values, and a numeric array index, like this:

    array(0 => 'field 1 val', 'field1_name'=> 'field 1 val',
          1 => 'field 2 val', 'field2_name'=> 'field 2 val', etc);
    

    Specifying either MYSQL_ASSOC or MYSQL_NUM will only retrieve either the associative values or the numerically indexed values respectively.

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

Sidebar

Ask A Question

Stats

  • Questions 469k
  • Answers 469k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer They really are two very different things, and serve different… May 16, 2026 at 2:48 am
  • Editorial Team
    Editorial Team added an answer IP port numbers are 16-bit unsigned integers. Therefore 65,535 is… May 16, 2026 at 2:48 am
  • Editorial Team
    Editorial Team added an answer b = a[:-1] + (a[-1]*2,) What I'm doing here is… May 16, 2026 at 2:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.