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 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 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 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

Related Questions

I have the following code <html> <head> <title>Test</title> <style type=text/css> <!-- body,td,th { color:
I have the following file: <html> <head> <title></title> <link rel=css type=text/css href=/empty.css title=css />
Consider the following markup: <!DOCTYPE html> <html> <head> <title>Test Page</title> <link href=screen.css rel=stylesheet />
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
<code> <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>jQuery.pager.js Test</title> <link href=Pager.css rel=stylesheet type=text/css /> <script src=jquery-1.2.6.min.js type=text/javascript></script>
I am using the following html page: <html> <head> <title>AJAX Example</title> <meta http-equiv=Content-Type content=text/html;
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
I am using this HTML <html> <head> <Title>EBAY Search</title> </head> <script language=JavaScript src=ajaxlib.js></script> <body>
I have the following HTML <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server> <title></title> <style> .box {

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.