suf3r Posted April 19, 2010 Share Posted April 19, 2010 Hello, My problem: Every time someone click on link from database script select id and show my content: 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; } 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? A bit explains: 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 both. If were exist aid (3) aid aid_text impr realimpr today 3 qwe 0 120 18 it will display as: asd, dsa, and qwe. (EDIT: copied my post from another forum, maybe in this forum someone help me) Link to comment https://forums.phpfreaks.com/topic/199053-random-row-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.