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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:54:11+00:00 2026-06-10T15:54:11+00:00

Old ASP developer migrating to PHP. I writ a PHP script to retrieve entries

  • 0

Old ASP developer migrating to PHP. I writ a PHP script to retrieve entries from an MS SQL Database and display. Looks like this:

<?php
$query = "SELECT DateUploaded, Title ";
$query .= "FROM TableName ";

$result = mssql_query($query);

$numRows = mssql_num_rows($result); 
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; 

while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["DateUploaded"] . $row["Title"] . "</li>";
}
?>

Now when I want to get it to display echoing it just on the page works fine. Using this section of code:

while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["DateUploaded"] . $row["Title"] . "</li>";
}

However when I try and put it into a table Ive created to display it it doesn’t seem to work, although I’ve read a few tutorials and feel it should, it is also similar to a technique I used to use in ASP.

Looks like this:

<TABLE cellSpacing=1 cellPadding=2 align=center bgColor=#aaaaaa border=0 width="100%" class="logintbl">
            <TR>
              <TD bgColor=whitesmoke colSpan=0><B>News</B></td>
            </tr>
            <tr>
                <td bgColor=#ffffff>
                    <table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
                        <tr>
                            <td align="center" valign="bottom">&nbsp;<font color="#4d71a1"><b>Date Uploaded</b></font>&nbsp;</td>
                            <td align="center" valign="bottom">&nbsp;<font color="#4d71a1"><b>News Title</b></font>&nbsp;</td>
                            <td align="center"></td>

                        </tr>

                        <tr bgcolor="#eeeeee">

                        <tr bgcolor="#ffffff">

                            <td align="center"><?php echo $row["DateUploaded"]; ?></td>
                            <td align="center"><?php echo $row["Title"]; ?></td>
                            <td align="center">
                            <A href="NewsUpdate.php?id="><img src="images/0013-pen.gif" width="16" height="16" alt="" border="0"></A>&nbsp;&nbsp;&nbsp;
                            <a href="NewsManage.php?do=del&id=" return false;">
                                <img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
                            </a>

                            </td>

                        </tr>

                        <tr><td colspan="7">&nbsp;</td></tr>
                        <tr>
                            <td colspan="7" align="center">
                            </td>
                        </tr>

                    </table>
                </td>
            </tr>
        </table>

I’m probably doing it totally wrong, but could someone point me in the right direction please?

  • 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-10T15:54:12+00:00Added an answer on June 10, 2026 at 3:54 pm

    Start the while loop right before the row with the data,
    and end it right after that.

    <table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
        <!-- header row here -->
    
        <?php 
            $alterColor = true;
            while ($row = mssql_fetch_array($result)) {  // start while 
    
            // alternating bg color for rows
            $color = ($alterColor) ? "#fff" : "#eee";  
            $alterColor = !$alterColor;
        ?>
        <tr bgcolor="<?php echo $color; ?>">
    
             <td align="center"><?php echo $row["DateUploaded"]; ?></td>
             <td align="center"><?php echo $row["Title"]; ?></td>
             <td align="center">
                 <A href="NewsUpdate.php?id="><img src="images/0013-pen.gif" width="16" height="16" alt="" border="0"></A>&nbsp;&nbsp;&nbsp;
                 <a href="NewsManage.php?do=del&id=" return false;">
                     <img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
                 </a>
    
             </td>
    
         </tr>
         <?php } // end while ?>
    </table>
    

    PS One of these seems to be extra, are they there for alternating color or something like that:

     <tr bgcolor="#eeeeee">
    
     <tr bgcolor="#ffffff">
    

    You should not really have a tr within a tr directly.

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

Sidebar

Related Questions

hey again stackoverflowers I'm migrating a website from old ASP (in VBScript) and there's
I have a templating system that looks similar to old-style ASP code. I run
I'm writing an old asp page to insert Session variables into a database to
I'm migrating an old vb desktop app to an ASP.NET web application version. The
I have a bunch of old classic ASP pages, many of which show database
I remember when I switched from Classic ASP to PHP many years ago, and
We have an old Access 2000 database that we need to pull data from
I have an old asp app I am moving to a new server with
I am updating an old asp site to cakephp - the old site has
I have several horrors of old ASP web applications. Does anyone have any easy

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.