【问题标题】:Working on the follow user feature in a php mysql application在 php mysql 应用程序中处理跟随用户功能
【发布时间】:2013-05-15 06:40:18
【问题描述】:

问题说明:我正在开发我的应用程序中的关注用户功能,并且需要一些。 我有一个优惠列表(由用户发布)显示在我的页面上,其中有一个“关注供应商”按钮。现在任何登录的用户都可以点击关注按钮并关注谁发布了报价

查询: 现在,如果用户已经关注该供应商,那么下次供应商发布任何报价时,关注按钮应替换为“关注”或“已关注”,因为他已经关注了他.
现在我可以在数组中获取登录用户关注的记录的结果。这是报价 div 的结构,报价在其中循环显示。

   <div class="box col2">
    <div class="innerBox"> <img src="http://codex.abc.com/upload_deals/files/221x208/<?php echo $resDeal['productImg'];?>">
      <p><?php echo $resDeal['productName']; ?></p>
      <p class="styleTxt">Added <?php echo $timer; ?> ago</p>
      <div class="clear"></div>
        <div class="over">
            <div class="twitter">
                <a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-url="http://www.abc.com/salesDetails.php?dealId=<?php echo $resDeal['saleId']; ?>">Tweet</a>
                <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
            </div>
            <!-- Facebook share button Start -->
            <div class="facebook">
                <fb:share-button type="button_count" href="http://www.abc.com/biggisalesDetails.php?dealId=<?php echo $resDeal['saleId']; ?>"></fb:share-button>

            </div>
            <!-- Facebook share button End -->
            <div class="pintrest">
                <!-- Pinterest button Start -->
                    <a href="javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)})());"><img alt="Pin It!" style='border: none;' src="http://assets.pinterest.com/images/pidgets/pin_it_button.png"/></a>
                    <!-- Pinterest button End -->
            </div>
            <div class="clear"></div>
            <a href="javascript:void(0)" class="red follow" saleId="<?php echo $resDeal['saleId'];?>">Follow Vendor</a>
        </div>
    </div>
    <div class="bottom">
      <h3><?php echo $resDeal['discount']; ?> Off</h3>
      <a href="biggisalesDetails.php?dealId=<?php echo $resDeal['saleId']; ?>">MORE</a>
    </div>
</div>

一次可以有超过 100 个优惠,那么检查用户是否关注发布优惠的供应商的最有效方法是什么?
我想获取数组中的值并在每个报价中检查供应商 ID 是否存在于用户后面的供应商数组中?像这样: select followedUserId from follow where userId =34.将其存储在一个数组中并检查是否报价供应商匹配它
这是一个好方法还是我可以以任何方式进一步优化它?
建议赞赏

【问题讨论】:

    标签: php mysql web-applications


    【解决方案1】:

    您建议的设计可以正常工作。 还有其他选择,例如:

    1. 获取将在页面上显示的供应商 ID 列表
    2. 获取用户关注的供应商 ID 列表
    3. 取两个列表的交集,给出将在页面上显示并被关注的所有供应商 ID 的列表

    但实际上,这些基本上是完成您所描述的事情的奇特方式。原因如下:(a) 有效,(b) 简单,(c) 易于理解,(d) 易于维护;我会坚持你所描述的选项,即。

    1. SELECT followuserid FROM follow WHERE userId=[insert user id here]
    2. 存储在数组中
    3. 每次输出一个item,检查vendor ID是否在数组中
    4. 使用 PHP if-else 块,有条件地向用户显示不同的内容。

    如果你真的想把它发挥到极致,你可以对数组进行排序并选择一个好的算法来搜索它,甚至可以构建一个新的数据结构,比如树,但这实际上是一个简单的问题,它非常复杂。

    【讨论】:

    • 我喜欢你的表达方式。感谢您的意见! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多