Forum Moderators: coopster
<html>
<head>
<basefont face="Arial">
</head>
<body>
<?php
error_reporting(E_ALL);
if (!isset($_POST['Submit'])) {
// form not submitted
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Search <input type="text" name="search"><br>
<select size="1" name="dropdown">
<option value="" selected>Search By...</option>
<option value="Manufacturer">Manufacturer</option>
<option value="Model">Model</option>
<option value="Socket">Socket</option>
<option value="Hyperthread">Hyperthread</option>
<option value="Cores">Cores</option>
</select>
<input type="Submit" value="Submit" name="Submit">
</form>
<?php
}
else {
// form submitted
// set server access variables
$host = "#*$!X";
$user = "#*$!X";
$pass = "#*$!X";
$db = "#*$!X";
$search = empty($_POST['search'])? die ("ERROR: Enter Search Criteria") : mysql_escape_string($_POST['search']);
$dropdown = empty($_POST['dropdown'])? die ("ERROR: Select from Dropdown") : mysql_escape_string($_POST['dropdown']);
// Open Connection
$connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host");
//Select Database
mysql_select_db($db) or die ("Unable to connect to database");
//Create Query
$query = "SELECT * FROM CPU WHERE $dropdown='$search'" or die (mysql_error());
$result = mysql_query($query) or die (mysql_error());
$num=mysql_numrows($result);
mysql_close($connect);
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$Manufacturer=mysql_result($result,$i,"Manufacturer");
$Model=mysql_result($result,$i,"Model");
$Socket=mysql_result($result,$i,"Socket");
$Hyperthread=mysql_result($result,$i,"Hyperthread");
$Cores=mysql_result($result,$i,"Cores");
echo "<br><b>$Manufacturer</b></br>$Model</b></br>Socket: $Socket</br>Hyperthread: $Hyperthread</br>Cores: $Cores<br>";
$i++;
}
}
?>
</body>
</html> $filter = '<table>
<tr>
<td>' . select_menu('Manufacturer', 'CPU') . '</td>
<td>' . select_menu('Cores', 'CPU') . '</td>
<td>' . select_menu('Socket', 'CPU') . '</td>
<td>' . select_menu('x64', 'CPU') . '</td>
<td>' . select_menu('Price', 'CPU') . '</td>
</tr>
</table>';
echo $filter;
$sql .= ' ORDER BY `Model` ASC';
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
echo '<table cellspacing="2">
From what I can see it looks like the results are being parsed into rows according to the number of results coming back from search.
<?php
$filter = '<table>
<tr>
<td><b>Manufacturer</b></td>
<td><b>Cores</b></td>
<td><b>Socket</b></td>
<td><b>64 Bit CPU</b></td>
<td><b>Average Price (USD)</b></td>
</tr>
<tr>
<td>' . select_menu('Manufacturer', 'CPU') . '</td>
<td>' . select_menu('Cores', 'CPU') . '</td>
<td>' . select_menu('Socket', 'CPU') . '</td>
<td>' . select_menu('x64', 'CPU') . '</td>
<td>' . select_menu('Price', 'CPU') . '</td>
</tr>
</table>';
echo $filter;
?>
<input type="Submit" value="Submit" name="Submit">
</form>
</body>
</html>
echo $filter;
[b]$filter = '[/b] with [b]echo '[/b] - it'll make your script a bit more efficient as you're not consuming any additional memory.