PHP/Mysql Not Displaying All Rows

I am running a php script and it is only displaying some rows, it seems to be random to which it displays. I have a sum function on the page and it adds up all the information correctly but will not show all the results. I have ran the scripts in phpmyadmin as well as MS Access and it displays all the data but when I run the script in my php document some of the data disappears. Below is my code.

[php]//Get PartID from URL
$iPartID = $_GET[“PartID”];

$oIteminfo = mysql_query("
SELECT Items.PartID, Items.VendorCost, Items.ProductName, Sum(Sales.AmountSold) AS SumOfAmountSold
FROM Items
LEFT JOIN Sales
ON Items.PartID = Sales.PartID
GROUP BY Items.PartID, Items.VendorCost, Items.ProductName
HAVING Items.PartID=$iPartID;

") or die(mysql_error());

while($row = mysql_fetch_array($oIteminfo))
{

ECHO "<br><table border=0 cellpadding=3>";
ECHO "<tr>";  
ECHO "<td><img src=\"http://www.wowauctionsales.com/images/".$iPartID.".jpg\"height='35' width='35'></td>";
ECHO "<td><h1>".$row['ProductName']."</h1></td>";
ECHO "</table>";   
ECHO "<B>Total Sold: </B>".$row['SumOfAmountSold']."<br>";
ECHO "<B>Vendor Price: </B>";
$number =$row['VendorCost'];
echo substr($number,-6,2).'g '.substr($number,-4,2).'s '.substr($number,-2,2).'c';

} 

$oIteminfo = mysql_query("
SELECT Sales.PartID, Sales.AmountSold, Sales.PricePerItem, Buyers.BuyerName, Buyers.Server, Sales.Day, Sales.Month, Sales.Year, Buyers.BuyerID
FROM Buyers
LEFT JOIN Sales
ON Buyers.BuyerID = Sales.BuyerID
WHERE Sales.PartID=$iPartID;

") or die(mysql_error());

while($row = mysql_fetch_array($oIteminfo))
{
ECHO “

”;
ECHO “”;
ECHO " ";
ECHO " ";
ECHO " ";
ECHO " ";
ECHO " ";
ECHO " ";
ECHO " ";

while($row = mysql_fetch_array($oIteminfo))
{
ECHO “

”;
ECHO “ “;
$number =$row[‘PricePerItem’];
echo “";
ECHO “";
ECHO “ “;
ECHO “ “;
ECHO “ “;
ECHO “ ";
} 

ECHO “

Amount SoldPrice PerBuyerServerDayMonthYear
”.$row[‘AmountSold’]."”.substr($number,-6,2).'g '.substr($number,-4,2).'s '.substr($number,-2,2).‘c’.”<a href=“buyerinfo.php?BuyerID=”.$row[‘BuyerID’].”">".$row[‘BuyerName’]."”.$row[‘Server’]."”.$row[‘Day’].””.$row[‘Month’].””.$row[‘Year’].”
”;
} 

?>
[/php]

Any Suggestions would be greatly appreciated, as I am not sure where to start. I can debug some things but this is beyond my knowledge.

You are using obsolete code that has been completely removed from PHP. You are also ripe for an SQL Injection attack. You need to use PDO with prepared statements. And why are you echoing html and repeating the table headers in a loop? And outputting the database errors to the user is a severe security risk. Page formatting goes in an external CSS file, not in the markup. This is really bad code and you shouldn’t be using it.

https://phpdelusions.net/pdo

Sponsor our Newsletter | Privacy Policy | Terms of Service