0

このコードを 1 時間半かけて調べましたが、何が問題なのかわかりません。エラーは返されず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 に答える