Ok, here is my issue. I am trying to write a program that takes a database and pulls it into a 2d array, from there compares it with another 2d array and from there creates another 2d array that has a product name in the first column and how many of the fields in each row matched up. I have most of this done except for the part of comparing, it turns out weird and says that pretty much everything matches, but this doesn't even come close to being the case. Here is some code:
$quality = $_POST['quality'];
$db = mysql_connect("localhost", "username", "password")
or die ("could not connect, please contact system admin");
$selected = mysql_select_db(products, $db);
if ($selected == false)
echo mysql_errno() . ": " . mysql_error() . "<br/>";
$query = "SELECT * FROM `treadmills`";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
//Pulls DB into a two dimensional array//////////////////
while ($line = mysql_fetch_array($result))
{
for($i = 0; $i < 11; $i++)
{$table[$i][] = $line[$i];}
}
echo "<table>";
for ($row = 0; $row 11; $row++)
{
echo "<tr>";
for ($column = 0; $column <$numrows; $column++)
{
echo "<td>";
echo $table[$column][$row];
echo "</td>";
}
echo "</tr>";
}
////end db to 2d array///////////////////////
////put answers in a 2d array/////////
for ($count = 0; $count < $numrows; $count++)
{
$compare[1][$count] = $_POST['motor'];
$compare[2][$count] = $_POST['speed'];
$compare[3][$count] = $_POST['incline'];
$compare[4][$count] = $_POST['weight'];
$compare[5][$count] = $_POST['quality'];
}
for ($row = 0; $row < 11; $row++)
{
echo "<tr>";
for ($column = 0; $column <$numrows; $column++)
{
echo "<td>";
echo $compare[$column][$row];
echo "</td>";
}
echo "</tr>";
}
////end 2d array answer code block///
///in theory.... compare, and display them////
for ($row = 0; $row < 11; $row++)
{
$products[0][$row] = $table[0][$row];
for ($column = 0; $column <$numrows; $column++)
{
if($compare[$column][$row] == $table[$column][$row])
{
$products[1][$row] = $products[1][$row] + 1;
}
}
}
for ($row = 0; $row < 11; $row++)
{
echo "<tr>";
for ($column = 0; $column <$numrows; $column++)
{
echo "<td>";
echo $products[$column][$row];
echo "</td>";
}
echo "</tr>";
}
I outputed the arrays into tables a couple of times for testing purposes, any body have any ideas on my problem? Thanks in advance!