0

在过去的一个半小时里,我一直在查看这段代码,但我不知道出了什么问题。它不返回任何错误,并且while使用查询调用的循环工作正常,但mysql_num_rows不会工作。

在我阅读代码之前,我想让你知道我已经尝试在查询中消除所有额外的混乱,例如,Order By但它仍然会引发警告。

编码:

    <?php
    global $_SESSION,$os_DB,$ui,$count;
    //Loggedin
    if($_SESSION['login']!=1)
    {
        print "You must be logged in.";
        include($root . 'footer.php');
        exit;
    }
    //Check banned account
    elseif($ui['level']=="2"){
        print "Sorry but your account is banned.";
        include($root . 'footer.php');
        exit;
    }
    //Check email verified
    elseif($ui['email_check']=="0"){
        print "Sorry but your account has not been verified, to verify your account now please visit <a href='index.php?index=verify&email=".$ui['email']."'>THIS LINK</a>.";
        include($root . 'footer.php');
        exit;
    }
    date_default_timezone_set('America/New_York');
    $country= $ui['country'];
    $dates=mysql_query("SELECT * FROM `contest` WHERE `countries` LIKE '%$country%'");
    $timestamp = time();

    $getcontests = $os_DB->query("SELECT * FROM contest WHERE date_1 <= '$timestamp' AND date_2 >= '$timestamp' AND countries LIKE '%$country%'");
        $num = $os_DB->num($getcontests);

            if($num == 0){
            print"<td colspan='4'>There are currently no active contests</td>";
            }
            else
            {

    while ($dat = mysql_fetch_array($dates)) {
    $tname = preg_replace('/\s+/', '', $dat['name']);
///////////Problem Area vvvv////////////////////////
    $places="(SELECT * FROM `".$tname."_contest` WHERE `username` <> 'admin' AND `completed` >= '".$dat['min_offers']."' ORDER BY `completed` DESC LIMIT ".$dat['rewards'].")";
    $results=mysql_query($places) or die(mysql_error());

    if ($dat['rewards'] == 1){
    $reward = "".$dat['reward_1']."";
    }
    else if ($dat['rewards'] == 2){
    $reward = "".$dat['reward_1'].",".$dat['reward_2']."";
    }
    else if ($dat['rewards'] == 3){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3']."";
    }
    else if ($dat['rewards'] == 4){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4']."";
    }
    else if ($dat['rewards'] == 5){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5']."";
    }
    else if ($dat['rewards'] == 6){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5'].",".$dat['reward_6']."";
    }
    else if ($dat['rewards'] == 7){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5'].",".$dat['reward_6'].",".$dat['reward_7']."";
    }
    else if ($dat['rewards'] == 8){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5'].",".$dat['reward_6'].",".$dat['reward_7'].",".$dat['reward_8']."";
    }
    else if ($dat['rewards'] == 9){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5'].",".$dat['reward_6'].",".$dat['reward_7'].",".$dat['reward_8'].",".$dat['reward_9']."";
    }
    else if ($dat['rewards'] == 10){
    $reward = "".$dat['reward_1'].",".$dat['reward_2'].",".$dat['reward_3'].",".$dat['reward_4'].",".$dat['reward_5'].",".$dat['reward_6'].",".$dat['reward_7'].",".$dat['reward_8'].",".$dat['reward_9'].",".$dat['reward_10']."";
    }

    $rewardsa = explode(",", $reward);
    $i=0;
    $a=1;

    // Offers Contest

    if(time() <= $dat['date_2'] && time() >= $dat['date_1'] && $dat['type'] == offer) {
    print" <table width ='100%'><tr><th align='center'><font size='4'>{$dat['name']}</font></th><th align='right'><font size='1'>".date("m/d/Y h:i A", $dat['date_1'])."-".date("m/d/Y h:i A", $dat['date_2'])."</font></th></tr></table><br />".$dat['desc']."<br /><font size='1' color='white'>You must complete offers worth at least ".$dat['min_points']." points or $".$dat['min_cash']." to count towards contest!<br /><br />
    You must also complete at least ".$dat['min_offers']." offers in order to be eligible for winnings.</font><br /><br />";
    print" <table width ='100%'><tr><th align='left'>Place</th><th align='center'>User</th><th align='right'>Prize</th><th align='right'>Completed</th></tr>";

    if(mysql_num_rows($results == 0)){
    if($dat['r_type'] == points){
    print"  <tr><td align='left'>{$a}</td><td align='center'>......</td><td align='right'>{$rewardsa[$i]} points</td><td align='right'>--</td></tr>";
    }
    if($dat['r_type'] == cash){
    print"  <tr><td align='left'>{$a}</td><td align='center'>......</td><td align='right'>$".$rewardsa[$i]."</td><td align='right'>--</td></tr>";
    }
    $i++;
    $a++;
    }


    while ($place = mysql_fetch_array($results)) {
    if($dat['r_type'] == points){
    print"  <tr><td align='left'>{$a}</td><td align='center'>{$place['username']}</td><td align='right'>{$rewardsa[$i]} points</td><td align='right'>{$place['completed']}</td></tr>";
    }
    if($dat['r_type'] == cash){
    print"  <tr><td align='left'>{$a}</td><td align='center'>{$place['username']}</td><td align='right'>$".$rewardsa[$i]."</td><td align='right'>{$place['completed']}</td></tr>";
    }
    $i++;
    $a++;
    }
    }
    }
    }

    ?>  
    </table>
4

3 回答 3

4

在您的代码中替换mysql_num_rows($results == 0)mysql_num_rows($results) == 0

于 2012-11-23T06:03:20.210 回答
4

你应该mysql_num_rows($results) == 0改用。

于 2012-11-23T06:05:36.623 回答
1

if(mysql_num_rows($results == 0)){

应该

if(mysql_num_rows($results) == 0){
于 2012-11-23T06:04:02.427 回答