asked on
<form name="form" action="cat.php" method="get">
<!--<input type="hidden" name="p" value=''/>-->
<SELECT NAME=p>
<option>SELECT CATEGORY</option>
<option value='Adapters & Couplers'>Adapters & Couplers</option>
<option value='Audio Video Cables'>Audio Video Cables</option>
<option value='Audio Video Devices'>Audio Video Devices</option>
<option value='Bulk Cable'>Bulk Cable</option>
<option value='Cat5e & Cat6 Cables'>Cat5e & Cat6 Cables</option>
<option value='Connectors'>Connectors</option>
<option value='DVI'>DVI</option>
<option value='Fiber Cables'>Fiber Cables</option>
<option value='HDMI'>HDMI</option>
<option value='Home Distribution'>Home Distribution</option>
<option value='KVM Cables & Switches'>KVM Cables & Switches</option>
<option value='Monitor Cables'>Monitor Cables</option>
<option value='Network Cables'>Network Cables</option>
<option value='Network Devices'>Network Devices</option>
<option value='PC Cables'>PC Cables</option>
<option value='Power Cords & Chargers'>Power Cords & Chargers</option>
<option value='Retail Items'>Retail Items</option>
<option value='SCSI'>SCSI</option>
<option value='Tools & Testers'>Tools & Testers</option>
<option value='USB'>USB</option>
<option value='VGA'>VGA</option>
<option value='Wall Plates'>Wall Plates</option>
</select>
<input type="submit" name="Submit" value="Search" />
</form>
<?
//Connect to DB
mysql_connect(" "," "," ") or die("Unable to connect to SQL server");
mysql_select_db(" ") or die("Unable to SELECT DB");
$Limit = 10; //Number of results per page
$SearchString=$_POST["p"]; // Get the search term
If($SearchString == "") $SearchString=$_GET["p"]; // Get the search term
If($SearchString == "") {
Echo"No results found for $SearchString <BR> Please enter a valid search term";
exit();
}
$page=$_GET["page"]; //Get the page number to show
If($page == "") $page=1; //If no page number is set, the default page is 1
// NEED ASSISTANCE HERE
$SearchResult=mysql_query("SELECT DISTINCT * FROM `products` WHERE `Category` = '$SearchString'") or die(mysql_error());
While($row2 = mysql_fetch_object($SearchResult)) {
Echo $row2->Subcategory . " ";
}
//Get the number of results
$SearchResult=mysql_query("SELECT * FROM `products` WHERE `Category` = '$SearchString'") or die(mysql_error());
$NumberOfResults=mysql_num_rows($SearchResult);
//Get the number of pages
$NumberOfPages = (ceil($NumberOfResults/$Limit)>=20) ? 8 : ceil($NumberOfResults/$Limit);
$SearchResult=mysql_query("SELECT * FROM `products` WHERE `Category` = '$SearchString' LIMIT " . ($page-1)*$Limit . ",$Limit") or die(mysql_error());
Echo $NumberOfResults . " ";
Echo "results for";
Echo " ";
Echo $SearchString;
Echo "<BR><BR>";
$Nav="";
If($page > 1) {
$Nav .= "<A HREF=\"cat.php?page=" . ($page-1) . "&p=" .urlencode($SearchString) . "\"><< Prev </A> ";
}
For($i = 1 ; $i <= $NumberOfPages ; $i++) {
If($i == $page) {
$Nav .= "<font size=+1><B> $i </B></FONT>";
}Else{
$Nav .= "<A HREF=\"cat.php?page=" . $i . "&p=" .urlencode($SearchString) . "\"> $i </A>";
}
}
If($page < $NumberOfPages) {
$Nav .= " <A HREF=\"cat.php?page=" . ($page+1) . "&p=" .urlencode($SearchString) . "\">Next >> </A>";
}
Echo $Nav;
Echo "<BR><BR>";
While($row = mysql_fetch_object($SearchResult)) {
Echo "<form name='form' action='product.php' method='GET'>";
Echo "<input type='hidden' name='UPC' value=".$row->UPC." />";
Echo $row->ProductName . " ";
Echo $row->Sku . " ";
Echo $row->UPC . " ";
Echo "<img src=";
Echo "http://www.cablestogo.com/assets/product_images/category_favorites_images/";
Echo $row->PictureSku;
Echo ".jpg>";
Echo "<input type='submit' name='Submit' value='More Info' />";
Echo "<HR width=500>";
Echo "</form>";
}
Echo "<BR><BR>" . $Nav;
?>
ASKER
ASKER
ASKER
$SearchResult2=mysql_query("SELECT DISTINCT `Subcategory` FROM `products` WHERE `Category` = '$SearchString' ") or die(mysql_error());
$num_result=mysql_num_rows($SearchResult2);
print "<table>";
$i=0;
while($record=mysql_fetch_array($SearchResult2))
{
if (($i % 3) == 0) print "<tr>";
print "<td><b>{$record[Subcategory]}</b></td>";
if (($i % 3) == 2) print "</tr>";
$i++;
}
#If we finished the above while loop with $i%3 < 2 then print the final </tr> tag:
if ( $i > 0 && ($i-1) % 3 < 2) print "</tr>";
print "</table>";
ASKER
$SearchResult2=mysql_query("SELECT DISTINCT `Subcategory` FROM `products` WHERE `Category` = '$SearchString' ") or die(mysql_error());
$num_result=mysql_num_rows($SearchResult2);
print "<table>";
$i=0;
while($record=mysql_fetch_array($SearchResult2))
{
if(strlen($record[Subcategory])>0) {
if (($i % 3) == 0) print "<tr>";
print "<td><b>{$record[Subcategory]}</b></td>";
if (($i % 3) == 2) print "</tr>";
$i++;
}
}
#If we finished the above while loop with $i%3 < 2 then print the final </tr> tag:
if ( $i > 0 && ($i-1) % 3 < 2) print "</tr>";
print "</table>";
ASKER
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
ASKER
Both of your solutiions worked! Thanks! Below is the table structure... I think I need some type of array?? to list the results in 3 columns without duplicating?
Thanks!!
Echo "<TABLE><TR>";
$SearchResult=mysql_query(
While($row2 = mysql_fetch_object($Search
Echo "<TD>"; // Not sure what to do right here??
Echo $row2->Subcategory . " ";
Echo "</TD>";
}
Echo "</TR></TABLE>";