Table: Distributor - dist_id
Table: menus - custid
itemno
Table: load_sheet - id
cat1
cat2
Table: categories - id
Relationships: Distributor.dist_id = menus.custid
menus.itemno = load_sheet.id
categories.id = load_sheet.cat1 OR categories.id = load_sheet.cat2
Goal: Logged in at a distributor (id: 353619). Display ONLY categories that have load_sheets that match whats in the distributors menu.
NOTE: The code below was originally designed to display ALL the categories (whether or not there were load_sheets under them).
Code:$userid = isset($_REQUEST['id']) ? $_REQUEST['id'] : $_SESSION['userid']; $currDate = date("m-d-Y"); $catquery="SELECT * from categories ORDER BY id ASC"; $catresult=mysql_query($catquery); $catnum=mysql_num_rows($catresult); if($catnum>0){ echo '<form method="post" action="process_order.php?userid='. $userid. '">'; $rCnt=1; while($catobj=mysql_fetch_object($catresult)) { $catID=$catobj->id; echo '<table width="535" border="0" align="center" class="fmenu" cellpadding="0">'; echo '<tr style="color: #6c7376;"><th align="left"> <font size="3">'.$catobj->name.'</font></th></tr>'; echo '<tr><td colspan="2" align="left" style="padding-left: 3px;"><i>'.str_replace("\r\n","<br />",$catobj->special).'</i></td></tr>'; $lsquery="SELECT * FROM load_sheet INNER JOIN menus ON menus.custid = '$userid' AND load_sheet.autoID = menus.itemno WHERE (cat1='$catID' OR cat2='$catID')"; if (isset($_REQUEST['id'])) { $lsquery .= "AND dateStart <= '$currDate' AND dateEnd >= '$currDate'"; } $lsresult=mysql_query($lsquery); $lsnum=mysql_num_rows($lsresult); if($lsnum>0){ //----....etc


Reply With Quote
Bookmarks