stop serve ads after user point going low

Started on the old forum in January 2013 · view the original in the archive · old links redirect here

17 replies · 5,749 views · started 13 years ago · 1 min read

TL;DR · summary of 17 replies
  • - php script needs integration with the database query for checking user points.
  • - Error in SQL syntax found, but solution provided does not work on the server environment.
  • - Code approach using conditional statement inside PHP ad code is suggested to check if user's points are greater than a minimum value before serving ads.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

4 participants
Nepsalone Developer · 76 posts #1

any coder plz help me how to stop serve ads after user points gettin low and set by minimum points in adcell mobi script

http://nepalwap.com 1st Nepali Mobile site...

Nepsalone Developer · 76 posts #2
<?php
require_once("../includes/config.php");
require_once("../includes/functions.php");
ob_start();
db_connect();
$uid = htmlspecialchars($_GET['uid']);
$ua = htmlspecialchars($_GET['HTTP_USER_AGENT']);
$ip = htmlspecialchars($_GET['REMOTE_ADDR']);
$adult = htmlspecialchars($_GET['adult']);
$mode = htmlspecialchars($_GET['mode']);
if($mode == 'live')
{
if($adult == 'on')
{
$sql = mysql_query("SELECT * FROM adverts WHERE pause='0' AND approved='1' AND userid !='$uid' AND ORDER BY RAND() LIMIT 1") or die(mysql_error());
}
else
{
$sql = mysql_query("SELECT * FROM adverts WHERE pause='0' AND approved='1' AND adult='0' AND userid !='$uid' AND points >='30' ORDER BY RAND() LIMIT 1") or die(mysql_error());
}
while($ad = mysql_fetch_array($sql))
{
   $t = htmlspecialchars($ad['title']);
   $l = htmlspecialchars($ad['link']);
   $imp = $ad['imps']+1;
   mysql_query("UPDATE adverts SET imps='".$imp."' WHERE id='".$ad['id']."'") or die(mysql_error());
   
   $adv = mysql_fetch_array(mysql_query("SELECT * FROM advertiser WHERE id='".$ad['userid']."'")) or die(mysql_error());
   $it1 = $adv['today_imps']+1;
   $ti1 = $adv['total_imps']+1;
   mysql_query("UPDATE advertiser SET today_imps='$it1', total_imps='$ti1' WHERE id='".$ad['userid']."'") or die(mysql_error());
   
   $pub = mysql_fetch_array(mysql_query("SELECT * FROM publisher WHERE id='".$uid."'")) or die(mysql_error());
   $it2 = $pub['today_imps']+1;
   $ti2 = $pub['total_imps']+1;
   mysql_query("UPDATE publisher SET today_imps='$it2', total_imps='$ti2' WHERE id='".$uid."'") or die(mysql_error());
   $ph = explode(" ",$ua);
   $title = str_ireplace("%phn%", "$ph[0]", "$t");
   echo"<a href='".SITE_URL."/serve/click/".$ad['userid']."/".$uid."/".base64_encode($l)."'>$title</a>";
}
}
else
{
echo"<a href='".SITE_URL."/serve/test/".base64_encode("http://nepalwap.com/ad")."'>Test AD: Free Mobile Downloads!</a>";
}
mysql_close();
?>

http://nepalwap.com 1st Nepali Mobile site...

Nepsalone Developer · 76 posts #4
<?php
 $ap = mysql_fetch_array(mysql_query("SELECT points FROM advertiser WHERE id='$id'"));
   $pp = mysql_fetch_array(mysql_query("SELECT points FROM publisher WHERE id='$id'"));?>

http://nepalwap.com 1st Nepali Mobile site...

GumSlone Administrator Principal · 1,690 posts #5
$sql = mysql_query("SELECT adverts.* FROM adverts, advertiser WHERE adverts.pause='0' AND adverts.approved='1' AND adverts.userid !='$uid' AND advertiser.id=adverts.userid AND advertiser.points>0 ORDER BY RAND() LIMIT 1") or die(mysql_error());

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Nepsalone Developer · 76 posts #8

-- phpMyAdmin SQL Dump -- version 3.3.9 -- phpMyAdmin

-- Host: localhost -- Generation Time: Jan 16, 2013 at 11:03 AM -- Server version: 5.5.8 -- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /; /!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /; /!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /; /!40101 SET NAMES utf8 */;

-- -- Database: ads


-- -- Table structure for table advertiser

CREATE TABLE IF NOT EXISTS advertiser ( id int(10) NOT NULL, points int(20) NOT NULL DEFAULT '0', today_is date NOT NULL DEFAULT '0000-00-00', today_imps int(10) NOT NULL, today_clicks int(10) NOT NULL, total_imps int(10) NOT NULL, total_clicks int(10) NOT NULL, total_ads int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- -- Dumping data for table advertiser

INSERT INTO advertiser (id, points, today_is, today_imps, today_clicks, total_imps, total_clicks, total_ads) VALUES (1, 1330, '2013-01-16', 0, 0, 1598, 962, 0), (3, 500, '2013-01-04', 262, 4, 262, 4, 0), (4, 450, '2013-01-16', 0, 0, 0, 0, 0);

Added after 12 minutes:

gums bro plz help me if you want full database msgs me because im unable to upload my full data

http://nepalwap.com 1st Nepali Mobile site...

Nepsalone Developer · 76 posts #12

im unable to post error msgs now because im usin mobile. if you post edited code in zip then i upload ds file in my server after im able to show error msgs. Sorry for bad english . Hope u help me

Nepsalone wrote: im unable to post error msgs now because im usin mobile. if you post edited code in zip then i upload ds file in my server after im able to show error msgs. Sorry for bad english . Hope u help me

here is serve dir all files in zip

http://nepalwap.com 1st Nepali Mobile site...

Attachments: Srv.zip
GumSlone Administrator Principal · 1,690 posts #13
<?php
require_once("../includes/config.php");
require_once("../includes/functions.php");
ob_start();
db_connect();
$uid = htmlspecialchars($_GET['uid']);
$ua = htmlspecialchars($_GET['HTTP_USER_AGENT']);
$ip = htmlspecialchars($_GET['REMOTE_ADDR']);
$adult = htmlspecialchars($_GET['adult']);
$mode = htmlspecialchars($_GET['mode']);
if($mode == 'live')
{
if($adult == 'on')
{
$sql = mysql_query("SELECT adverts.* FROM adverts, advertiser WHERE adverts.pause='0' AND adverts.approved='1' AND adverts.userid !='$uid' AND advertiser.id=adverts.userid AND advertiser.points>0 ORDER BY RAND() LIMIT 1") or die(mysql_error()); 
}
else
{
$sql = mysql_query("SELECT adverts.* FROM adverts, advertiser WHERE adverts.pause='0' AND adverts.approved='1' AND adverts.adult='0' AND adverts.userid !='$uid' AND advertiser.id=adverts.userid AND advertiser.points>0 ORDER BY RAND() LIMIT 1") or die(mysql_error()); 
}
while($ad = mysql_fetch_array($sql))
{
   $t = htmlspecialchars($ad['title']);
   $l = htmlspecialchars($ad['link']);
   $imp = $ad['imps']+1;
   mysql_query("UPDATE adverts SET imps='".$imp."' WHERE id='".$ad['id']."'") or die(mysql_error());
   
   $adv = mysql_fetch_array(mysql_query("SELECT * FROM advertiser WHERE id='".$ad['userid']."'")) or die(mysql_error());
   $it1 = $adv['today_imps']+1;
   $ti1 = $adv['total_imps']+1;
   mysql_query("UPDATE advertiser SET today_imps='$it1', total_imps='$ti1' WHERE id='".$ad['userid']."'") or die(mysql_error());
   
   $pub = mysql_fetch_array(mysql_query("SELECT * FROM publisher WHERE id='".$uid."'")) or die(mysql_error());
   $it2 = $pub['today_imps']+1;
   $ti2 = $pub['total_imps']+1;
   mysql_query("UPDATE publisher SET today_imps='$it2', total_imps='$ti2' WHERE id='".$uid."'") or die(mysql_error());
   $ph = explode(" ",$ua);
   $title = str_ireplace("%phn%", "$ph[0]", "$t");
   echo"<a href='".SITE_URL."/serve/click/".$ad['userid']."/".$uid."/".base64_encode($l)."'>$title</a>";
}
}
else
{
echo"<a href='".SITE_URL."/serve/test/".base64_encode("http://nepalwap.com/ad")."'>Test AD: Free Mobile Downloads!</a>";
}
mysql_close();
?>

post the error which you get with this code

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Nepsalone Developer · 76 posts #14

check it nepalwap.com/ad/index.php

Added after 4 minutes:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '! ='4' AND advertiser.id=adverts.userid AND advertiser.points>0 ORDER BY RAND() ' at line 1

http://nepalwap.com 1st Nepali Mobile site...

GumSlone Administrator Principal · 1,690 posts #15
CREATE TABLE `advertiser` (
  `id` int(10) NOT NULL,
  `points` int(20) NOT NULL DEFAULT '0',
  `today_is` date NOT NULL DEFAULT '0000-00-00',
  `today_imps` int(10) NOT NULL,
  `today_clicks` int(10) NOT NULL,
  `total_imps` int(10) NOT NULL,
  `total_clicks` int(10) NOT NULL,
  `total_ads` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Daten für Tabelle `advertiser`
--

INSERT INTO `advertiser` (`id`, `points`, `today_is`, `today_imps`, `today_clicks`, `total_imps`, `total_clicks`, `total_ads`) VALUES
(1, 1330, '2013-01-16', 0, 0, 1598, 962, 0),
(3, 500, '2013-01-04', 262, 4, 262, 4, 0),
(4, 450, '2013-01-16', 0, 0, 0, 0, 0);

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `adverts`
--

CREATE TABLE `adverts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userid` int(11) NOT NULL,
  `pause` int(1) NOT NULL,
  `approved` int(1) NOT NULL,
  `adult` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Daten für Tabelle `adverts`
--

INSERT INTO `adverts` (`id`, `userid`, `pause`, `approved`, `adult`) VALUES
(1, 1, 0, 1, 0),
(3, 3, 0, 1, 0),
(4, 4, 0, 1, 0);

and

SELECT adverts . * 
FROM adverts, advertiser
WHERE adverts.pause = '0'
AND adverts.approved = '1'
AND adverts.userid != '1'
AND advertiser.id = adverts.userid
AND advertiser.points >0
ORDER BY RAND( ) 
LIMIT 1

works for me, see the attachment

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Attachments: Bildschirmfoto 2013-01-16 um 17.00.50.png
Nepsalone Developer · 76 posts #16

not work in my host any other idea plz http://nepalwap.com/ad/go/?uid=4&adult=on&mode=live working bt error showing in php adcode. Php adcode link http://nepalwap.com/ad/ad.php

my php ad code

<?php
/*
Do not change this code without prior permission from NepalWAP ad Network!
If You Do So Then Your Account Will Be Suspended Without Any Warning !!!
*/

function show_nepalwap_ad()
{          $ua = $_SERVER["HTTP_USER_AGENT"];
   $ip = isset ($_SERVER["HTTP_X_FORWARDED_FOR"]) ?
 $_SERVER["HTTP_X_FORWARDED_FOR"] : 
$_SERVER["REMOTE_ADDR"];
   if(strstr($ip, ','))
   {
      $ips = explode(',', $ip);
      $ip = $ips[0];
   }
    $params  = 'uid='.urlencode('4'); // set your uniqe id

    $params .= '&HTTP_USER_AGENT='.urlencode($ua);
    $params .= '&REMOTE_ADDR='.urlencode($ip);
    $params .= '&adult='.urlencode('1');  // set 1 for on value or 0 for off value

    $params .= '&mode='.urlencode('live');  // set mode 'live' to show ads 'test' to disable ads
    // send ad request
    $url = "http://nepalwap.com/ad/go/?".$params;
    $timeout = 5; 
    $ch  = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $html = curl_exec($ch);
    curl_close($ch);
    if($html !== false) return $html;
    else return "";
}

?>
<?php
// copy this snippet elsewhere on your page for display more of ads
echo show_nepalwap_ad();
?>

http://nepalwap.com 1st Nepali Mobile site...

kevk3v Senior · 332 posts #17

Get the user's points into a variable and then do something like this

<?php
if($user_points>1500)
{
///show ads
}
?>

The ">" means "more than"...

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close