防止PHP中的表中的重复域条目

时间:2018-05-17 05:55:47

标签: php mysql sql

以下代码显示的是包含网站链接和域名列表的表格

<?php 
$sql = "SELECT * FROM $tables[socials] WHERE active = 'yes'";
$s = "";
if (nmr($sql) >= 1) {
    $s = ", channels: [";
    $qry = qry($sql);
    while ($x=$qry->fetch_assoc()) {
        $s .= "'$x[name]',";
    }
    $s .= "]";
}
$styles = array(
    "position" => ['left','inner','right'],
    "theme" => ['circle','squere'],
);
foreach ($styles as $st => $sts) {
    if (!empty($_GET[$st])) {
        if (in_array($_GET[$st], $sts)) {
            $$st = $_GET[$st];
        }else{
            $$st = $sts[0];
        }
    }else{
        $$st = $sts[0];
    }
}
 header('Content-Type: text/javascript'); ?>(function() {
        document.writeln('\
                <table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td>\
                            <div>Top Last :</div>\
                            <?php 
                                $qry = qry("SELECT * FROM ".$tables['websites']." WHERE active = 'yes' AND sticky = 'yes' LIMIT 10");
                                while ($website = $qry->fetch_assoc()) :
                                    qry("UPDATE ".$tables['websites']." SET views = views + 1 WHERE id = $website[id]");
                                    $array_key = explode(",", $website['name']);
                                    if (count($array_key) <= 1) {
                                        $randkey = $website['name'];
                                    }else{
                                        $randkey = $array_key[array_rand($array_key)];
                                    }
                            ?>
                                    <div>\
                                        <a href="<?=$website['link'];?>" target="_blank"><?=$randkey;?></a>\
                                    </div>\
                                    <div>\
                                        <span><?=@parse_url($website['link'])['host'];?></span>\
                                    </div>\
                            <?php endwhile ?>
                </td></tr></table>\
        ');

})();

说明

<a href="<?=$website['link'];?>" target="_blank"><?=$randkey;?></a>它显示我从管理面板

添加的链接和名称

请注意$randkey&#34; name&#34;在comma(name1,name2,name3)之间随机添加

<?=@parse_url($website['link'])['host'];?>显示网站

的域名

最终结果:

        <table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td>\
            <div>\
                    <div>Top Last shared:</div>\
                        <div class="newone">\
                            <div>\
                                <a href="http://yahoo.com/email" target="_blank">Emails</a>\
                            </div>\
                            <div>\
                                <span>yahoo.com</span>\
                            </div>\
                        </div>\
                        <div class="newone">\
                            <div>\
                                <a href="https://linkedin.com/" target="_blank">search for Job</a>\
                            </div>\
                            <div>\
                                <span>linkedin.com</span>\
                            </div>\
                        </div>\
                        <div class="newone">\
                            <div>\
                                <a href="http://yahoo.com/chat" target="_blank">Chat</a>\
                            </div>\
                            <div>\
                                <span>yahoo.com</span>\
                            </div>\
                        </div>\
                        </div>\ 
        </td></tr></table>\

现在,在上面的例子中它不止一次显示yahoo.com,

现在需要停止为每个条目复制域,并且每次运行时只能随机查看其中一个。

0 个答案:

没有答案