need some help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    need some help

    i can't understand why ads are also showing when it is paused , please can any1 tell me what is wrong in this ?
    PHP Code:
    $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
            while($advid = mysql_fetch_array($advids))
            {
                if($adult == 'adult')
                {
                    $sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
                }
                else
                {
                    $sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND adult='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
                }
                while($ad = mysql_fetch_array($sql))
                {
                    $t = htmlspecialchars($ad['title']);
                    $l = htmlspecialchars($ad['link']);
    ......................... 
    
    in database paused=1 but still ads are showing , why?

    #2
    Originally posted by razor View Post
    i can't understand why ads are also showing when it is paused , please can any1 tell me what is wrong in this ?
    PHP Code:
    $sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND paused='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
    
    ......................... 
    
    in database paused=1 but still ads are showing , why?
    following the OR keyword include the paused='0' column

    Comment


      #3
      thanks bro, thank you again for sorting my logical mistake...

      Comment


        #4
        one more problem plz help

        PHP Code:
        if(!empty($uid) && !empty($adult))
            {
                $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
                while($advid = mysql_fetch_array($advids))
                {
                    if($adult == 'adult')
                    {
                        $sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND paused='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
                    }
                    else
                    {
                        $sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND paused='0' AND adult='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
                    }
                    while($ad = mysql_fetch_array($sql))
                    {
                        $t = htmlspecialchars($ad['title']);
                        $l = htmlspecialchars($ad['link']);
                        mysql_query("UPDATE adverts SET imps=(imps+1) WHERE id='".$ad['id']."'") or die(mysql_error());
                        mysql_query("UPDATE advertiser SET today_imps=(today_imps+1), total_imps=(total_imps+1) WHERE id='".$ad['userid']."'") or die(mysql_error());
                        echo"<div class='adbox'>";
                            $ph = explode(" ",$ua);
                            $title = str_ireplace(":phn:", "$ph[0]", "$t");
                            $av = $ad['userid'];
                            $pb = $uid;
                            $ad = $ad['akey'];
                            $rn = str_shuffle('ADZVILLA.COM');
                            $converter = new Encryption;
                            $str = $rn.'-'.$av.'-'.$pb.'-'.$ad.'-'.$country;
                            $encoded = $converter->encode($str);
                            echo"<sup><font color=\"red\"><small>ad </small></font></sup><a href='".SITE_URL."/serve/click/".urlencode($encoded)."'>$title</a>";
                        echo"</div>";
                    } 
        
        code is like this but the problem i want to show only 5 random ads , but its not showing only five, what is the mistake plz help any1...

        Comment


          #5
          What is the output, how many records are shown?
          What script is that, i think the entire script needs to be benchmark/Optimize with such query. Thus those query could be join to prevent heavy resource from what I've seen.

          Comment


            #6
            Originally posted by xor View Post
            What is the output, how many records are shown?
            What script is that, i think the entire script needs to be benchmark/Optimize with such query. Thus those query could be join to prevent heavy resource from what I've seen.
            it is showing all the active ads
            look here http://adzvilla.com/serve/ads/4/adult

            Comment


              #7
              Originally posted by xor View Post
              What is the output, how many records are shown?
              What script is that, i think the entire script needs to be benchmark/Optimize with such query. Thus those query could be join to prevent heavy resource from what I've seen.
              it is showing all the active ads
              look here http://adzvilla.com/serve/ads/4/adult
              use mobile browser

              Comment


                #8
                Its showing exactly 5 records.

                Comment


                  #9
                  Originally posted by xor View Post
                  Its showing exactly 5 records.
                  no, i opened and showing 6 result, screenshot here2012-08-26_2328 - mrpaul92's library

                  Comment


                    #10
                    The query seems ok, as its limited to 5, to get a better understanding of these queries id have to rewrite them, however to hard-code it add these 2 lines
                    PHP Code:
                    <?PHP
                    //first line
                    $i = 0;
                    
                    while($ad = mysql_fetch_array($sql))
                    {
                        //second line
                        
                        if($i >= 5){
                            break;
                        }
                        $i++;
                        
                        
                        $t = htmlspecialchars($ad['title']);
                        $l = htmlspecialchars($ad['link']);
                        
                        mysql_query("UPDATE adverts SET imps=(imps+1) WHERE id='".$ad['id']."'") or die(mysql_error());
                        mysql_query("UPDATE advertiser SET today_imps=(today_imps+1), total_imps=(total_imps+1) WHERE id='".$ad['userid']."'") or die(mysql_error());
                        
                        echo"<div class='adbox'>";
                        $ph = explode(" ",$ua);
                        $title = str_ireplace(":phn:", "$ph[0]", "$t");
                        $av = $ad['userid'];
                        $pb = $uid;
                        $ad = $ad['akey'];
                        $rn = str_shuffle('ADZVILLA.COM');
                        $converter = new Encryption;
                        $str = $rn.'-'.$av.'-'.$pb.'-'.$ad.'-'.$country;
                        $encoded = $converter->encode($str);
                        echo"<sup><font color=\"red\"><small>ad </small></font></sup><a href='".SITE_URL."/serve/click/".urlencode($encoded)."'>$title</a>";
                        echo"</div>";
                    }

                    Comment


                      #11
                      sorry xor, thanks for trying to help me but it does not work, anyway i have fixed it now by changing the first while loop , there was logical problem...... anyhow thank you

                      Comment


                        #12
                        Originally posted by razor View Post
                        sorry xor, thanks for trying to help me but it does not work, anyway i have fixed it now by changing the first while loop , there was logical problem...... anyhow thank you
                        The few lines of modification actually does work if u written in correctly.

                        Your welcome

                        Comment


                          #13
                          at last done it...
                          code will be
                          PHP Code:
                          if(!empty($uid) && !empty($adult))
                              {
                          $i=0;
                                  $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
                          for($i=0;$i<5;$i++)
                          {
                          
                                  $advid = mysql_fetch_array($advids);
                                  
                          
                                      if($adult == 'adult')
                                      { 
                          
                          hmm... thanks xor for idea of looping
                          Last edited by razor; 26.08.12, 21:35.

                          Comment


                            #14
                            A quick note. it may work, however the syntax is invalid
                            PHP Code:
                            //this line is not needed
                            $i=0;
                            
                            //because you  declare var $i here in the for loop
                            for($i=0;$i<5;$i++)
                            
                            //also, the correct way to limit results to 5 would be
                            $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."' LIMIT 5"); 
                            
                            Bare in mind that results maybe less than 5, due to the fact that you further filter the results from the above query( $adult= ) or enough rows not available.

                            Comment


                              #15
                              Originally posted by razor View Post
                              at last done it...
                              code will be
                              PHP Code:
                              if(!empty($uid) && !empty($adult))
                                  {
                              $i=0;
                                      $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
                              for($i=0;$i<5;$i++)
                              {
                              
                                      $advid = mysql_fetch_array($advids);
                                      
                              
                                          if($adult == 'adult')
                                          { 
                              
                              hmm... thanks xor for idea of looping
                              Don't forget to use LIMIT in your query. Otherwise it will eat your RAM and slow down your site.
                              $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."' LIMIT 5");
                              Last edited by Rksk; 27.08.12, 07:24.

                              Comment

                              Working...
                              X