Forum Moderators: coopster
<?php
echo "<table class=\"comptbl\"><tr>";
echo "<td><table class=\"comptbl\">";
echo "<tr><td class=\"label\">Model Number</td></tr>";
echo "<tr><td class=\"label\">Model Name</td></tr>";
echo "<tr><td class=\"label\">Description</td></tr>";
echo "<tr><td class=\"label\"># of Memory Slots</td></tr>";
echo "<tr><td class=\"label\">Maximum Memory</td></tr>";
echo "<tr><td class=\"label\">PCIe Support</td></tr>";
echo "<tr><td class=\"label\">PCI Support</td></tr>";
echo "<tr><td class=\"label\">ISA Support</td></tr>";
echo "<tr><td class=\"label\">SATA Support</td></tr>";
echo "<tr><td class=\"label\">USB Support</td></tr>";
echo "<tr><td class=\"label\">OnBoard Video</td></tr>";
echo "<tr><td class=\"label\">Onboard Ethernet</td></tr>";
echo "<tr><td class=\"label\">Front Side Bus Speed</td></tr>";
echo "</table></td>";
foreach($_POST as $name => $value) {
if ($value!="Compare")
{
mysql_select_db("tti_site", $ttiConn) or die('Sorry, could not connect to database');
$query = "SELECT * from tblsbccompare where modelNum = $value";
$result = mysql_query($query) or die('Could not get values');
while($row=mysql_fetch_array($result, MYSQL_ASSOC))
{
$mNum = $row['modelNum'];
$mName = $row['modelName'];
$mDesc = $row['modelDesc'];
$mQty = $row['memQty'];
$mMax = $row['memMax'];
$mPCIe = $row['PCIe'];
$mPCI = $row['PCI'];
$mISA = $row['ISA'];
$mSATA = $row['SATA'];
$mUSB = $row['USB'];
$mVideo = $row['Video'];
$mEthernet = $row['Ethernet'];
$mFSB = $row['FSB'];
}
echo "<td><table class=\"comptbl\">";
echo "<tr><td class=\"comphdr\">$mNum</td></tr>";
echo "<tr><td>$mName</td></tr>";
echo "<tr><td>$mDesc</td></tr>";
echo "<tr><td>$mQty</td></tr>";
echo "<tr><td>$mMax</td></tr>";
echo "<tr><td>$mPCIe</td></tr>";
echo "<tr><td>$mPCI</td></tr>";
echo "<tr><td>$mISA</td></tr>";
echo "<tr><td>$mSATA</td></tr>";
echo "<tr><td>$mUSB</td></tr>";
echo "<tr><td>$mVideo</td></tr>";
echo "<tr><td>$mEthernet</td></tr>";
echo "<tr><td>$mFSB</td></tr>";
echo "</table></td>";
}
}
echo "</tr>";
echo "</table>";
?>
The above code gives me the output I want as far as the data itself is concerned. However, as you can see, there are a couple of issues.
1) I have to create tables for each column of data (I am trying to make the item's data columnar). This means that if any row wraps, then suddenly my rows are uneven and data can't be analyzed by row. This would not be an issue if I could simply have one table and place each item and its data in its own column
2) Probably the bigger issue. I am running a SELECT statement for EACH product that was selected on my original form. I am thinking there should be some way to do ONE query (using the IN keyword, I imagine), and feed all that to an array or similar, then add it to the table. Unfortunately I am still a bit green with PHP, combining it with MySQL especially.
Any tips/advice on this would be appreciated, as I want to learn the right way to do it. :0)
2) The only method I could conceive of you doing this is to expand your OR on the select statement with a loop. Create the first part of the statement, then use your foreach loop.
$szQuery = "SELECT * FROM tblsbccompare WHERE ";
$szOrs = "";
foreach($_POST as $name => $value)
{
if($value != "Compare")
{
if($szOrs != "")
{
$szOrs = $szOrs . " OR ";
}
$szOrs = $szOrs . "modelNum = $value";
}
}
if($szOrs != "")
{
$szQuery = $szQuery . $szOrs;
}
Another possible method would be to take the high and low values from the $value parameter and get every product in between those values, then compare them to $value before inserting them into your array.
highest_value and lowest_value do not, to my knowledge, exist, but I am lazy:
$big = highest_value($_POST);
$small = lowest_value($_POST);
$nX = 0;
$szQuery = "SELECT * FROM tblsbccompare WHERE modelNum <= $big AND modelNum >= $small";
$oResults = $oSQL->query($szQuery);
while($oRow = $oResults->fetch_array())
{
if(in_array($oRow["modelNum"], $_POST))
{
$aProdList[$nX] = $oRow;
$nX++;
}
}