문제

I am trying to make a simple stock exchange application in PHP and have a completely working session-based login system. Now I am having an issue listing the stocks a user has in a table. When I run the exact query that I have made in my PHP code in Navicat, the query returns the desired results, but PHP will not use the information to populate the table. The 0 in current value is a placeholder until I implement the YQL code required to pull stock information. I have a screenshot showing just about everything necessary to view what I am talking about:

screenie

My PHP code for the query is here:

echo "Welcome to your portfolio overview. Here you can view many of your statistics.<br><br><b>Balance:</b> " . $balance . "<br><b>Debt:</b> " . $debt . "<br>";
$sql2 = "SELECT * FROM `trades` WHERE buyerid=$uid";
$result2 = mysql_query($sql2);
echo "<table border=2 cellpadding=5>";
echo "<tr><td><b>Symbol</b></td><td><b>Purchase Price</b></td><td><b>Current Value</b></td></tr>";
while($row2 = mysql_fetch_array($result2));
{
    echo "<tr><td>" . $row2['identifier'] ."</td><td>" . $row2['purchaseprice'] . "</td><td>" . 0 . "</td></tr>";
}
echo "</table>";
도움이 되었습니까?

해결책

You have an erroneous semicolon after the while condition:

while($row2 = mysql_fetch_array($result2));
                                          ^ -- remove this

With this semicolon in place, you loop over an empty statement until your resultset is exhausted and then you execute the echo statement contained within your braces (with $row2 now false) irrespective of the while loop before.

다른 팁

Line 6:

while($row2 = mysql_fetch_array($result2));

must be

while($row2 = mysql_fetch_array($result2))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top