$category = array($linens, $china, $kitchen, $lighting, etc...etc...etc...); //example of element inside category $linens = array($napkins, $towels, $sheets, $drapes, etc...etc...etc...); //example of element inside linens. these are associative arrays. $napkins = array("qtyReq" => $cmsVar1, "stillNeed" => $cmsVar2, "price" => $cmsVar3, etc...etc...etc...);

//seach.php <form method="POST" action="results.php"> Search Word: <input type="text" name="query"> <input type="SUBMIT" value="Search"> </form>
<?php //results.php rough draft //imagine each result is a link. if you click the link, //it will go to registry.php and a unique ID# will //be sent as well $sql = mysql_query("SELECT column1, column2 FROM myTable WHERE column1 LIKE %$query% OR column2 LIKE %$query%") or die (mysql_error()); while(list($column1, $column2)=mysql_fetch_array($sql)) { echo "Result: $column1, $column2 <br />"; } ?>
<?php //registry.php /* here i will write a function to connect to the correct SQL table using the newlywed's ID# as the locator.*/ $categories = array("Flatware", "China Room", "Crystal Room", "Kitchenware", "Silver, Stainless", "Pewter", "Serverware & Entertaining", "Gourmet", "Lighting", "Smells", "Paper Goods", "Baby & Kids", "Housekeeping", "Religious", "Holidays", "Bath", "Body & Fragrance", "Luggage & Accessories", "Mens", "Womens", "Jewelry", "Collectibles", "The Wall"); /*unfinished array containing 23 'category' elements, and another 6 array elements within each category element.*/ $twoDarray = array(array(......; for($c = 0; $c < count($categories); $c++) { $twoDarray[$c] = $categories[$c]; if(!$twoDarray[$c]) { exit; } else { echo "<TABLE BORDER=1><TR><TH COLSPAN=7>Category: ". $categories[$i] ."</TH></TR>"; echo "<TR><TH>Item</TH><TH>Quantity Requested</TH><TH>Still Needs</TH><TH>Price</TH><TH>View</TH><TH>Quantity</TH><TH>Buy</TH></TR>"; for($i = 0; $i < count($twoDarray[$c]); $i++) { if(!$twoDarray[$c][$i]) { exit; } else { echo "<TR><TD>"; echo $twoDarray[$c][$i]; echo "</TD><TD>Add to Cart Button</TD></TR>"; } } echo "</TABLE>\n\n"; } } ?>
What is the structure of your database table(s)?
You don't need to create the arrays $twoDarray and $category.
You can just select this from the DB, uless the categories will never change..
<!-- SEARCH.PHP --> <form method="POST" action="results.php"> First Name:<input type="text" name="fname"><BR> Last Name:<input type="text" name="lname"><FONT COLOR="FF0000" SIZE="-1">(required)</FONT><BR> <SELECT NAME="regDate"> <OPTION VALUE="">Select an Event Date <OPTION VALUE="">Month | Year <OPTION VALUE="">Month | Year <OPTION VALUE="">Month | Year <OPTION VALUE="">Month | Year <OPTION VALUE="">Month | Year </SELECT> <BR> <input type="SUBMIT" value="Search"> </form>
<?php // results.php trim($lname); if (!$lname) { echo "<FONT COLOR="FF0000">You have not filled the required fields. Please try again.</FONT>"; exit; } @ $db = mysql_connect("host", "newlyWed_DB", "pass"); if(!$db) { echo "Error: Could not connect to the database. Please try again later."; exit; } $sql = mysql_query("SELECT brideLname, groomLname FROM my_search_table WHERE brideLname LIKE '%". $lname ."%' OR groomLname LIKE '%". $lname ."%'") or die(mysql_error()); $result = mysql_query($sql); $num_result = mysql_num_rows($result); echo "Number of matches: ". $num_result ."\n"; if(!$result) { echo "Sorry, there were no matches for your query. Please try again."; } else { echo "<TABLE BORDER=1><TR><TH>Bride</TH><TH>Groom</TH><TH>Event Date</TH><TH>View Registry</TH></TR>"; for($i=0; $i < $num_result; $i++) { $row = mysql_fetch_array($result); echo "<TR><TD>". $row['brideFname'] ." ". $row['brideLname'] ."</TD><TD>". $row['groomFname'] ." ". $row['groomLname'] ."</TD><TD>". $row['eventDate'] ."</TD><TD>". $row['uID'] ."</TD></TR><br />"; } echo "</TABLE>"; } mysql_close($db); ?>
<?php //registry.php @ $db = mysql_connect("host", "registryDB", "pass"); if(!$db) { echo "Error: Could not connect to the database. Please try again later."; exit; } $sql = mysql_query("SELECT * FROM ". $uID ." ORDER BY category") or die(mysql_error()); $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if(!$result) { echo "There are no items in the registry for this couple at this time. Please try again later."; //connect to search_DB to add newlywed's names instead of 'this couple' } else { for($i = 0; $i < $numrows; $i == $i) //<-- no increment here. look inside while loop for increment { echo "<TABLE BORDER=1><TR><TH COLSPAN=7>Category: ". $row['category'] ."</TH></TR>"; echo "<TR><TH>Item</TH><TH>Quantity Requested</TH><TH>Still Needs</TH><TH>Price</TH><TH>View</TH><TH>Quantity</TH><TH>Buy</TH></TR>"; while($row['category'] == $row['category']) //<-- pretty sure this will stop the while loop if it hits a new category. right? { echo "<TR><TD>". $row['item'] ."</TD><TD>". $row['qty_req'] ."</TD><TD>". $row['still_need'] ."</TD><TD>". $row['price'] ."</TD><TD>". $row['view'] ."</TD><TD>Input Field</TD><TD>Add to Cart</TD></TR>"; $i++; } echo "</TABLE><br /><br />"; } } ?>
| DaniWeb Message | |
| Cancel Changes | |