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>';
Your
whileloop 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.
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.