在管理面板中显示特定供应商的产品

时间:2014-12-17 15:50:44

标签: php mysql

我有一个基本的管理面板,我可以看到所有供应商和所有已添加的产品。在供应商页面中,我想添加一个链接,当单击该链接时,将仅显示/添加/编辑该供应商的产品。有关如何做到这一点的任何线索?

************编辑**************
这就是我的产品页面的样子。此页面显示所有产品。

<?php
                            $sno=$pagination->getLimit() + 1;
                            $sql2 = $sql1." limit " . $pagination->getLimit() . ", ". $rowsperpage; 
                            $res2 = @mysql_query($sql2, $connection) or die("failed");
                            $i = 1; 
                            $c=1;
                            $k=0;       
                            while($res=mysql_fetch_array($res2))
                            {
                            ?>
                  <tr <?php if($k==0) { echo 'class=""';  } else { echo 'class="row_color"'; } ?> id="row<?php echo $i;?>">
                    <td class="table_text"><?php echo $sno; ?>.</td>
                    <td class="table_text" style="line-height:12pt;">
                     <?php
                               if($res['off_status']=='N')
                               {
                               ?>
                               <span style="padding-left: 0px;font-weight:bold;color:#E8E8E8;"><?php echo $res['Name']; ?></span> 
                               <?php
                               }
                               else
                               {
                               ?>
                               <?php echo $res['Name']; ?>
                               <?php 
                               } 
                               ?>                   
                    </td>
                    <td class="table_text" style="line-height:12pt;">
                     <?php
                                $rest_name = mysql_query("SELECT * FROM `restaurants` WHERE `RestID`='$res[RestID]'");
                                $res_fet = mysql_fetch_array($rest_name);
                               if($res['off_status']=='N')
                               {
                               ?>
                               <span style="padding-left: 0px;font-weight:bold;color:#E8E8E8;"><?php echo $res_fet['Name']; ?></span> 
                               <?php
                               }
                               else
                               {
                               ?>
                               <?php echo $res_fet['Name']; ?>
                               <?php 
                               } 
                               ?>                   
                    </td>
                    <td class="table_text" style="line-height:12pt;"> <?php
                               if($res['off_status']=='N')
                               {
                               ?>
                               <span style="padding-left: 0px;font-weight:bold;color:#E8E8E8;"><?php echo date('d-m-Y',strtotime($res['StartDate']));?></span>
                                <?php
                               }
                               else
                               {
                               ?>
                               <?php echo date('d-m-Y',strtotime($res['StartDate']));?>
                               <?php 
                               } 
                               ?>                              </td>
                    <td class="table_text" style="line-height:12pt;"><?php
                               if($res['off_status']=='N')
                               {
                               ?>
                               <span style="padding-left: 0px;font-weight:bold;color:#E8E8E8;"><?php echo date('d-m-Y',strtotime($res['ExpiryDate']));?></span>
                                <?php
                               }
                               else
                               {
                               ?>
                               <?php echo date('d-m-Y',strtotime($res['ExpiryDate']));?>
                               <?php 
                               } 
                               ?></td>
                    <td class="table_text"><table width="68" height="68" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffebc1">
                      <tr>
                        <td align="center"><?php
                        if($res['Image'] != "")
                        {
                        ?>
                          <img src="../images/offers/thumb/<?php echo $res['Image']; ?>" border="0" />
                          <?php
                        }
                        else
                        {
                        ?>
                          <img src="../images/no_image.jpg" width="88" height="76" border="0" />
                          <?php
                        }
                        ?>                        </td>
                        </tr>
                      </table></td>
                    <td align="center" class="table_text"><a href="view_level.php?id=<?php echo $res['OfferID']; ?>&amp;rpage=<?php echo base64_encode($cont); ?>"><img src="images/icon/level.png" width="47" height="43" border="0" /></a></td>
                    <td align="center" class="table_text"><a href="set_link.php?id=<?php echo base64_encode($res['OfferID']); ?>&amp;rpage=<?php echo base64_encode($cont); ?>"><img src="images/link.png" alt="" width="47" height="43" border="0" /></a></td>
                    <td align="center" class="table_text"><a href="edit_offer.php?id=<?php echo base64_encode($res['OfferID']); ?>&rpage=<?php echo base64_encode($cont); ?>"><img src="images/icon/edit_icon.gif" width="16" height="15" border="0" /></a></td>
                    <td align="center" class="table_text"><a href="view-offer-details.php?id=<?php echo base64_encode($res['OfferID']); ?>"><img src="images/icon/view_icon.gif" width="16" height="16" border="0" /></a></td>
                               <?php
                               if($res['off_status']=='Y')
                               {
                               ?>
                    <td align="center" class="table_text"><a href="view-offer-active.php?id=<?php echo base64_encode($res['OfferID']);?>" style=" color: #66CC00;text-decoration:none" rel="gb_page_center[550,300]">Active</a></td>
                               <?php 
                               }
                               else
                               {
                               ?>
                          <td width="15%" align="center" class="table_text">  <a href="view-offer-active.php?id=<?php echo base64_encode($res['OfferID']);?>" style=" color:#FF0066;text-decoration:none" rel="gb_page_center[550,300]">Inactive</a></td>
                              <?php 
                               }
                               ?>
                                 <td width="14%" align="center" class="table_text"><a href="view_offers.php?delete=<?php echo base64_encode($res['OfferID']); ?>&rpage=<?php echo base64_encode($cont); ?>" onclick="return confirm('Are You Sure?');"><img src="images/del.png" width="16" height="15" border="0" /></a></td>
                  </tr>
                  <?php
                        $c++;
                        $i++;
                        $k++;   
                        $sno++;
                        if($k==2)
                        {
                        $k=0;
                        }
                        }
                        ?>
                  <input type="hidden" name="acount" id="acount" value="<?php echo $i-1; ?>">
                </table>


这就是我所谓的上述页面的链接:

    <?php
$sel=mysql_query("select * from offers where OfferID='".$id."'") or die(mysql_error());
$fet=mysql_fetch_array($sel);
$rest=mysql_query("select * from restaurants where RestID='".$fet['RestID']."'") or die(mysql_error());
$restfet=mysql_fetch_array($rest);

$dd= $fet['Links'];
$rest_id=$fet['RestID'];
$sql_mlink=mysql_query("select * from offers where off_status='Y' and OfferID!='".$id."' and RestID='".$rest_id."' order by OfferID asc") or die(mysql_error());


$sql_query = mysql_query("SELECT * FROM offers where RestID='".$res['RestID']."'");
  $row = mysql_fetch_array($sql_query);
  //$res_count=mysql_num_rows($row);
 $sy = mysql_query("SELECT * FROM offers where RestID='".$res['RestID']."' and status='Y'");
 $res_count=mysql_num_rows($sy);
  $rw = mysql_fetch_array($sy);
?>
                             <td class="table_text">
                               <a href="view_offers.php?rest_id=<?php echo $row['RestID']; ?>" target="_blank">Menu</a>
                               </td>

1 个答案:

答案 0 :(得分:0)

你应该能够很容易地使用php获取并轻松调整你的SQL。

将供应商编号/转义名称添加到此页面的链接末尾...例如:

<a href='this-page.php?vendor=vendor-1'>vendor 1</a>

然后在页面的开头检查是否有供应商集,如果有,请为您的语句末尾创建一些额外的sql。如果不将额外的sql变量留空,则不添加任何内容:

if(!empty($_GET['vendor']))
{
$extra_sql = " AND vendor = ".$_GET['vendor'];
}
else
{
$extra_sql = "";
}

然后将$ extra_sql变量添加到现有SQL的末尾:

$rest=mysql_query("select * from restaurants where RestID='".$fet['RestID']."'".$extra_sql) or die(mysql_error());