Page 1 of 1

random id problem

Posted: Sun Apr 18, 2010 8:30 am
by suf3r
Hello,
My problem:
Every time someone click on link from database script select id and show my content:

Code: Select all

function GetRandomAd()

{

global $myDB;

$today = date('j');

$ql = "SELECT * FROM reklama WHERE today<>'$today' OR realimpr<impr OR impr=0 ORDER BY RAND() LIMIT 1";
$result = $myDB->Execute($ql) or die(GetDbError($myDB->ErrorMsg()));
$r_id = $result->Fields("aid");

$r_ad_text = $result->Fields("ad_text");

$r_today = $result->Fields("today");

$result->Close();

if ($r_id)

{

if ($today != $r_today) $ql = "UPDATE reklama SET realimpr=1, today='$today' WHERE aid='$r_id'";

else  $ql = "UPDATE reklama SET realimpr=realimpr+1 WHERE aid='$r_id'";

$result = $myDB->Execute($ql) or die(GetDbError($myDB->ErrorMsg()));

$result->Close();

}

return $r_ad_text;

}

function getAd()

{

global $myDB;

global $config;

$query1 = "SELECT * FROM reklama ORDER BY aid";

$result1 = $myDB->Execute($query1) or die(GetDbError($myDB->ErrorMsg()));

$f = 0;

$Repeat1__numRows = -1;

while (($Repeat1__numRows-- != 0) && (!$result1->EOF))
{

$tmp[$f]['n'] = $f + 1;

$tmp[$f]['aid'] = $result1->Fields("aid");

$tmp[$f]['ad_text'] = $result1->Fields("ad_text");
$tmp[$f]['impr'] = $result1->Fields("impr");

$tmp[$f]['realimpr'] = $result1->Fields("realimpr");

$tmp[$f++]['today'] = $result1->Fields("today");

$result1->MoveNext();

}

$result1->Close();

return $tmp;

}
Explains:
reklama - table name
aid - random id which select every time
http://utorrentz.projektas.lt/bla/edit.png

ad_text - text/image which will be showed
impr - max. image/text show per day
today - put's month day (ex. today is april 18, so it puts in this field 18)
realimpr - how many time image/text was showed today (if limit reached image/text doesn't apear, thats a impr point).


At this time script everytime select random id from aid and show it. It's possible that everytime get random id's from database but show/select not one, but them all?

Re: random id problem

Posted: Sun Apr 18, 2010 9:07 am
by lunarnet76
Your issue is that you want to have not just one random row but all of them but in a different order !? If that's it just remove the LIMIT 1!

Re: random id problem

Posted: Sun Apr 18, 2010 9:31 am
by suf3r
lunarnet76 wrote:Your issue is that you want to have not just one random row but all of them but in a different order !? If that's it just remove the LIMIT 1!
Everything with random rows ok, everytime then execute GetRandomAd, it's select random value which to display, and thats ok.
But problem is: it's select only one value from aid and display it. I wanna make it select all value from aid and display what's writed in aid_text.

Ex. Let's say i have:
(what aid aid_text ... explained upper)
aid aid_text impr realimpr today
1 asd 0 120 18

aid aid_text impr realimpr today
2 dsa 0 120 18

So, script execute GetRandomAd and it's select random aid, after page refresh it again choose random aid and display aid_text with wich it assigned.
I wanna make it to select all value from aid and display it.

Ex.
Let's say i open page, GetRandomAd executed and it choosed me to display aid (1), so in page/output i see: asd.
I refresh page, and GetRandomAd executed again, but this time it choosed display aid (2), so in page/output i see: dsa.

But how to make to select them all, so in page/output i see asd and dsa.

If were exist aid (3)
aid aid_text impr realimpr today
3 qwe 0 120 18

it will too display: asd, dsa, and qwe.

EDIT:
I have tested a bit with this line:

Code: Select all

$ql = "SELECT * FROM reklama WHERE today<>'$today' OR realimpr<impr OR impr=0 ORDER BY RAND() LIMIT 1";
I think it need's something change in this: ORDER BY RAND() .

Re: random id problem

Posted: Sun Apr 18, 2010 9:34 am
by lunarnet76
then replace

Code: Select all

$ql = "SELECT * FROM reklama WHERE today<>'$today' OR realimpr<impr OR impr=0 ORDER BY RAND() LIMIT 1";
by

Code: Select all

$ql = "SELECT * FROM reklama WHERE today<>'$today' OR realimpr<impr OR impr=0 ORDER BY RAND()";

Re: random id problem

Posted: Sun Apr 18, 2010 9:37 am
by suf3r
lunarnet76 wrote:then replace

Code: Select all

$ql = "SELECT * FROM reklama WHERE today<>'$today' OR realimpr<impr OR impr=0 ORDER BY RAND() LIMIT 1";
by

Code: Select all

$ql = "SELECT * FROM reklama WHERE today<>'$today' OR realimpr<impr OR impr=0 ORDER BY RAND()";
Sorry, but no luck, it's still display random ad_text after page refresh.