What I'm trying to do is really simple. I'm trying to run a query on my (mysql) database and sort it by the ExpID (INT(11), Primary, auto_inc).
When I run the query in phpMyAdmin, it sorts correctly. BUT, When I run the query through PHP code and output it using mysql_fetch_array(), it doesn't sort correctly. I've used this type of code several times before. Below is a snip of my code, and any help would be GREATLY appreciated.
Code: Select all
<?php
$result = mysql_query("select * from exploded where ProdPartNum = '$PartNum' ORDER BY ExpID");
if (!$result) echo "Cannot connect to database server-please try again later";
$num_rows = mysql_num_rows($result);
$columns=4;
if($num_rows!=0)
{
while($row = mysql_fetch_array($result))
{
$rows = ceil($num_rows / $columns);
$ExpID[] = $row['ExpID'];
$ExpKey[] = $row['ExpKey'];
$ExpProdPartNum[]=$row['ExpProdPartNum'];
$ExpProdDesc[] = $row['ExpProdDesc'];
}
....table setup....
for($i = 0; $i < $rows; $i++)
{
for($j = 0; $j < $columns; $j++)
{
if(isset($ExpProdPartNum[$i + ($j * $rows)]))
{
echo "<TR>\n";
echo "<TD>" . $ExpID[$i + ($j * $rows)] . "</TD>\n";
echo "<TD>" . $ExpKey[$i + ($j * $rows)] . "</TD>\n";
echo "<TD>" . $ExpProdPartNum[$i + ($j * $rows)] . "</TD>\n";
echo "<TD>" . $ExpProdDesc[$i + ($j * $rows)] . "</TD>\n";
echo "</TR>\n";
}
}
?>