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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:24:42+00:00 2026-05-16T21:24:42+00:00

for some reason the below code is outputting the correct ticker in the location

  • 0

for some reason the below code is outputting the correct ticker in the location of LPrice for all items, but only outputting the correct data for the second data element for PCT and PNL. Meaning, row 1 output only populating in one section, while row 2 populating in all correct sections. Note: there are currently only 2 elements in the table.

<?php
$host="localhost"; // Host name 
$username="abc"; // Mysql username 
$password="password"; // Mysql password 
$db_name="abc"; // Database name 
$tbl_name="portfolio"; // Table name
$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql="select * from ".$tbl_name.";";
$result = mysql_query($sql) or die(mysql_error()); 
echo '<table class="tickerContain">';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>TICKER</td>';
echo '<td>PRICE</td>';
echo '<td>CommIn</td>';
echo '<td>CommOut</td>';
echo '<td>DateIn</td>';
echo '<td>LPrice</td>';
echo '<td>%CHG</td>';
echo '<td>PNL</td>';

$tblOut='';
while ($row = mysql_fetch_array($result))
{
  $tick='';
  $tick=$row["ticker"];
  $tblOut.= '<tr>';
  $tblOut.= '<td id="'.$tick.'id">' . $row["id"] . '</td>';
  $tblOut.= '<td id="'.$tick.'ticker">' . $tick . '</td>';
  $tblOut.= '<td id="'.$tick.'price">' . $row["price"] . '</td>';
  $tblOut.= '<td id="'.$tick.'commissionIn">' . $row["commissionIn"] . '</td>';
  $tblOut.= '<td id="'.$tick.'commissionOut">' . $row["commissionOut"] . '</td>';
  $tblOut.= '<td id="'.$tick.'dateIn">' . $row["dateIn"] . '</td>';
  $tblOut.= '<td><textarea class="realTime"  id="'.$tick.'LPrice">'.$tick.'</textarea></td>';
  $tblOut.= '<td><textarea class="realTime"  id="'.$tick.'pctChange">'.$tick.'</textarea></td>';
  $tblOut.= '<td><textarea class="realTime"  id="'.$tick.'pnl">'.$tick.'</textarea></td>';
  $tblOut.= '</tr>';
}
echo $tblOut;
echo '</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-16T21:24:43+00:00Added an answer on May 16, 2026 at 9:24 pm

    Your while loop was closing the <tr> tag above it on every iteration, but there’s no way you could have seen that with that totally unreadable code.

    I took the liberty of tidying it up for you:

    You also had some entirely useless variables assigned. I fixed that too.

    <?php
    $host="localhost"; // Host name 
    $username="abc"; // Mysql username 
    $password="password"; // Mysql password 
    $db_name="abc"; // Database name 
    $tbl_name="portfolio"; // Table name
    $conn=mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql="select * from ".$tbl_name.";";
    $result = mysql_query($sql) or die(mysql_error());
    
    ?>
    
    <table class="tickerContain">
        <tr>
            <td>ID</td>
            <td>TICKER</td>
            <td>PRICE</td>
            <td>CommIn</td>
            <td>CommOut</td>
            <td>DateIn</td>
            <td>LPrice</td>
            <td>%CHG</td>
            <td>PNL</td>
    
        </tr>
        <?php while ($row = mysql_fetch_array($result)) : ?>
        <tr>
            <td id="<?php echo $row["ticker"]; ?>id">
                <?php echo $row["id"]; ?>
            </td>
            <td id="<?php echo $row["ticker"]; ?>ticker">
                <?php echo $row["ticker"]; ?>
            </td>
            <td id="<?php echo $row["ticker"]; ?>price">
                <?php echo $row["price"]; ?>
            </td>
            <td id="<?php echo $row["ticker"]; ?>commissionIn">
                <?php echo $row["commissionIn"]; ?>
            </td>
            <td id="<?php echo $row["ticker"]; ?>commissionOut">
                <?php echo $row["commissionOut"]; ?>
            </td>
            <td id="<?php echo $row["ticker"]; ?>dateIn">
                <?php echo $row["dateIn"]; ?>
            </td>
            <td>
                <textarea class="realTime" id="<?php echo $row["ticker"]; ?>LPrice">
                    <?php echo $row["ticker"]; ?>
                </textarea>
            </td>
            <td>
                <textarea class="realTime" id="<?php echo $row["ticker"]; ?>pctChange">
                    <?php echo $row["ticker"]; ?>
                </textarea>
            </td>
            <td>
                <textarea class="realTime" id="<?php echo $row["ticker"]; ?>pnl">
                    <?php echo $row["ticker"]; ?>
                </textarea>
            </td>
        </tr>
        <?php endwhile; ?>
    </table>
    

    Additionally, I would suggest moving your database code to another file, and including it into your scripts.

    Take a look at MVC Architecture (http://en.wikipedia.org/wiki/Model–view–controller), it will significantly help you keep your code clean.

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

Sidebar

Related Questions

I have the below code but for some reason I cannot get the correct
The below code works, but for some reason the $('#chart').fadeTo callback seems to create
The below code is in my javascript/jquery script, but for some reason Firebug tells
For some reason, the code below fails on the second line with run-time error
I've got the code below, but for some reason the Flash slider doesn't allow
For some reason in my below code, the replies array is NSLogging the correct
I have the below code to open a CSV file, but for some reason
See code below, for some reason it only works when I put a breakpoint
For some reason i'm getting an unexpected [ in the below line of code.
For some reason the code below isn't centering my Unordered List (I have the

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.