我对php / sql不太好 - 还在学习。
我试图得到它所以从用户数据库中随机选择5个url(有20个以上可供选择)并显示在页面上。如果用户没有在我们网站的成员区域填写所有20多个网址,我希望它跳过他们尚未填写的网址。
问题是选择并显示5是否为NULL并且在5之后停止。它不仅计算非空的。
我需要修理什么,我该如何解决?我从相关页面粘贴了整个代码 - 希望它能够理解我需要的东西......就像我说我对这些东西不太好。
<?php
include "config.php";
if ($_GET['r']) {
if($_COOKIE['referid']!=$_GET['r']) mysql_query("UPDATE members SET hits_unique=hits_unique+1,hits_visitor=hits_visitor+1 WHERE userid='".$_GET['r']."'");
else mysql_query("UPDATE members SET hits_visitor=hits_visitor+1 WHERE userid='".$_GET['r']."'");
setcookie('referid', $_GET['r'], time()+365*24*60*60);
setcookie('referrer', $_SERVER['HTTP_REFERER'], time()+365*24*60*60);
}
include 'headsplash.php';
echo '<body style="font-family: "Lato", sans-serif; background-color: black; color: white; height:100%; overflow:hidden;">';
echo '<script src="modernizr-0.9.min.js"></script>';
echo '<canvas id="theapt" style="width:100%; height:100%; position:fixed; top:0;left:0; background-color:black; z-index:-1;"></canvas>';
echo '<center><h1 id="congrats" style="font-size:55px; margin: 0 6px 20px;">'.$_GET['r'].' Recommends</h1></center>';
echo '<div style="margin-bottom:5px; font-size:17px; text-align:center;">';
echo '\'s Downline Builder</h2>';
echo '<div class="wall_back shadow" style="opacity: .9; width:478px; margin: 15px auto 0; border: 1px solid white; border-radius:10px; padding:20px; background-color: #161616;">';
//Get the user links
$ub = array();
$sql = mysql_query("SELECT * FROM builder WHERE userid = '".$_GET['r']."'");
if(@mysql_num_rows($sql)) $ub = mysql_fetch_array($sql);
$lastcat = "";
//Get the links for each site
$slist = mysql_query("SELECT s.*,c.name as catname FROM builder_sites s JOIN builder_cat c ON s.category=c.id ORDER BY RAND() LIMIT 5");
while($each = mysql_fetch_array($slist)) {
$user = $_GET['r'];
$found = 0;
while($found == 0) {
//Referrer exists?
$sql = mysql_query("SELECT m.referid FROM members m JOIN members r ON m.referid = r.userid WHERE m.userid = '".$_GET['user']."'");
if(@mysql_num_rows($sql)) {
$referrer = mysql_result($sql, 0);
$sql = mysql_query("SELECT site".$each['id']." FROM builder WHERE userid = '".$_GET['r']."'");
if(@mysql_num_rows($sql)) {
// Found a row, check if it's empty
$value = mysql_result($sql, 0);
if($value) {
//found a link, end the loop
$links = $value;
$found = 1;
} else {
//No link, next.
$user = $referrer;
}
} else {
//No row, next.
$user = $referrer;
}
} else {
//No more referrers, use default values
$links = $each['url'];
$found = 1;
}
}
if($lastcat != $each['category']) ;
$lastcat = $each['category'];
?>
<table width="50%" cellspacing="5" cellpadding="5">
<tr>
<form method="post"><a href="http://nullreferrer.com/go/?<? if($ub['site'.$each['id']]=="") echo $links; else echo $ub["site".$each['id']]; ?>" target="_blank"><? echo $each['desc']; ?></a><input type="hidden" name="sid" value="<? echo $each['id']; ?>">
<br><b><? echo $each['explain']; ?></b>
</form>
</tr>
</table>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-41048281-1', 'thedownliner.com');
ga('send', 'pageview');
</script>
<? }
echo '<center><h3><br><a href="http://thedownliner.com/?r='.$_GET['r'].'" ><button id="button-green">Get your FREE downline builder here</button></a></h3></center>';
echo '</div>';
echo '</div>';
mysql_close($dblink);
?>