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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:36:32+00:00 2026-05-15T01:36:32+00:00

I am relatively new to php and have a feeling that I am going

  • 0

I am relatively new to php and have a feeling that I am going the long way round when displaying data from mysql.

I have a table a I want to show a few fields from my database.

How would I achieve this without having to echo every bit of the table???

Here is the code:

     <?php
$query1 = mysql_send("SELECT firstname, lastname, email, user, country FROM customers WHERE id='".$_COOKIE['custid']."'");

while ($row = mysql_fetch_array($query1))

{

      echo     ' <table id="account_table" style="width:550px; border:none; ">
              <tr>
                <td width="155">Contact Name</td>';
      echo          '<td width="335">';

    echo $row['firstname'] ;
    echo '&nbsp;';
    echo $row['lastname'];

    echo '</td>
              </tr>
              <tr>
                <td>Email Address</td>
          <td>';
   echo $row['email'];

  echo '  </td>
             </tr>
              <tr>
                <td>Username</td>
                <td>' ;

    echo $row['user'];

    echo '</td>
              </tr>
              <tr>
                <td>Country</td>
                <td>';

    echo $row['country'];

    echo '</td>
              </tr>
              <tr>
                <td>Time Zone</td>
                <td>GMT+1</td>
              </tr>
              <tr>
                <td>Activated</td>
                <td>16 Dec 2009</td>
              </tr>
            </table>';

            }
?>
  • 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-15T01:36:32+00:00Added an answer on May 15, 2026 at 1:36 am

    You can fetch all data into an array first and then iterate over that array. There is no need to echo all that HTML with PHP.

    At the top of your file, you should do all the processing (i.e. getting, validating data) and in the remainder you just write plain HTML, only printing the values with PHP.

    This already gives you a certain degree of separation. Others mention template engines (Smarty, etc.). I don’t think that you really need that, because PHP itself is a template engine.
    Just don’t get tempted to do sophisticated stuff in your presentation 😉

    Also the alternative syntax for control structures is very useful for using in combination with the presentation as it is imho much more readable.


    I changed the table structure a bit, because you were not generation valid HTML (you create a lot tables with the same ID in your original code).
    This just generates one table, with a row for each customer.

    <?php
    $customers = array();
    $query1 = mysql_send("SELECT firstname, lastname, email, user, country FROM customers WHERE id='".$_COOKIE['custid']."'");
    
    while ($row = mysql_fetch_array($query1)) {
        $cusomters[] = $row;
    }
    ?>
    
    <table id="account_table" style="width:550px; border:none;">
        <tr>
           <th width="155">Contact Name</th>
           <th>Email Address</th>
           <th>Username</th>
           <th>Country</th>
           <th>Time Zone</th>
           <th>Activated</th>
        </tr>
    <?php foreach($customers as $customer): ?>
        <tr>           
            <td width="335">
                 <?php echo $row['firstname'] ?>
                 &nbsp;
                 <?php echo $row['lastname'] ?>
            </td>          
            <td><?php echo $row['email'] ?> </td>     
            <td><?php echo $row['user'] ?></td>           
            <td><?php echo $row['country'] ?></td>
            <td>GMT+1</td>
            <td>16 Dec 2009</td>
        </tr>
    <?php endforeach; ?>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to MYSQL and have had an issue that has been
I'm relatively new to PHP and have been writing a project using what I
i'm relatively new to php and mysql and would like to know how to
I'm relatively new with PHP and more so with XML. I have a script
I'm relatively new to PHP/mySQL and I'm trying to develop a portfolio of my
I'm relatively new to Nant, what i'd like to do is have a task
I am relatively new to PHP, but experienced Java programmer in complex enterprise environments
This may be a silly question, but as someone relatively new to PHP, I'm
I have the following code that is presenting a 'word-of-the-day', As I am relatively
I am relatively new to Cake PHP framework and was trying few things in

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.