Ocean West Posted March 2, 2015 Posted March 2, 2015 what do i need to change in this 3x code that worked as a custom block but currently doesn't work in 4x$this->DB->build( array( 'select' => 'ad_id', 'from' => 'nexus_ads', 'where' => 'ad_locations like "%fmf_square%"', 'and' => 'ad_active=1', 'order' => 'rand()' ) ); $this->DB->execute(); $i=0; while ( $row = $this->DB->fetch() ) { $ad_ids[] = $row['ad_id']; } foreach( $ad_ids as $ad_id ){ $i++; $str = file_get_contents( "{$this->settings['board_url']}/interface/advertisements.php?$ad_id" ) ; $str = preg_replace('/\<[\/]{0,1}div[^\>]*\>/i', '', $str); if($i==10) { echo $str . "<br>"; } else { echo $str . " "; } }
Mark Posted March 2, 2015 Posted March 2, 2015 $i = 0; foreach ( \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_advertisements', 'ad_location LIKE "%fmf_square%" AND ad_active=1' ), 'IPS\core\Advertisement' ) as $ad ) { $i++; $str = preg_replace( '/\<[\/]{0,1}div[^\>]*\>/i', '', $ad ); if( $i == 10 ) { echo $str . "<br>"; } else { echo $str . " "; } }
Flitterkill Posted March 2, 2015 Posted March 2, 2015 This should be cleaned up and stuck in the docs. A great example of 3 series vs 4 series changes on some core functionality.
Ocean West Posted March 2, 2015 Author Posted March 2, 2015 I am confused why is it now pulling from core advertisement and not from nexus_ads why is there two tables for ads?( i tried the above and it didn't work) Also I don't see in the code how it will randomize the results?
Mark Posted March 2, 2015 Posted March 2, 2015 It's just core_advertisements now. We moved the feature out of Commerce and into the core.Sorry I missed out the rand() order by clause. Add it as the 4th parameter to the select() method.
Ocean West Posted March 5, 2015 Author Posted March 5, 2015 So will there be some "cleanup" routine that drops old deprecated, columns, tables?Also I tried that bit of code but nothing will display.
Ocean West Posted March 15, 2015 Author Posted March 15, 2015 Ok i tried this code and multiple variations but nothing will display...my goal is every active square ad (with link) in random order[ ad01 ] [ad02] [ ad02 ] [ad03] [ ad04 ] [ad05] [ ad06 ] [ad07] [ ad08 ] [ad09] [ ad10 ] <br>[ ad12 ] [ad12] [ ad12 ] [ad13] [ ad14 ] [ad15] [ ad16 ] [ad17] [ ad18 ] [ad19] [ ad20 ]My old code produced this http://fmforums.com/ad_test.html which was used in a block that cached every few minutes which i then used with the external API - ( i know that is not ready yet - but still need to restore the adds to the site footer )
Ocean West Posted April 16, 2015 Author Posted April 16, 2015 I am really struggling with this new code - and can't get it to work at all. Can someone kindly point me in the right direction?
Ocean West Posted April 24, 2015 Author Posted April 24, 2015 55 Days later and I still can't figure this out -I have copied and pasted the code that @Mark posted but that doesn't do anything. I have tried to paste it into a block or even on a page, but I can't figure out the proper syntax.
newbie LAC Posted April 24, 2015 Posted April 24, 2015 55 Days later and I still can't figure this out -I have copied and pasted the code that @Mark posted but that doesn't do anything. I have tried to paste it into a block or even on a page, but I can't figure out the proper syntax. foreach ( \IPS\Patterns\ActiveRecordIterator change to foreach ( new \IPS\Patterns\ActiveRecordIterator
不中用 Posted April 25, 2015 Posted April 25, 2015 . Which one did you choose ? The correct one ? $i = 0; foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_advertisements', 'ad_active=1' ), 'IPS\core\Advertisement' ) as $ad ) { $i++; $str = preg_replace( '/\<[\/]{0,1}div[^\>]*\>/i', '', $ad ); if( $i == 10 ) { echo $str . "<br>"; } else { echo $str . " "; } } Try this code first without the LIKE MySQL Statement .. it is working for me, tested it .. .
Ocean West Posted April 25, 2015 Author Posted April 25, 2015 Wow awesome - this is showing promise! foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_advertisements', 'ad_active=1 AND ad_location=\'fmf_square\'' ), 'IPS\core\Advertisement' ) as $ad )the WHERE clause is in single quotes and that the text string i am searching on has to be escaped and quoted.so i have it rendering now but its one long list - need to strip out the <div><ul><li> tags...
不中用 Posted April 25, 2015 Posted April 25, 2015 Wow awesome - this is showing promise! foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_advertisements', 'ad_active=1 AND ad_location=\'fmf_square\'' ), 'IPS\core\Advertisement' ) as $ad )the WHERE clause is in single quotes and that the text string i am searching on has to be escaped and quoted.so i have it rendering now but its one long list - need to strip out the <div><ul><li> tags... .So you are using the LIKE too ?Think you will have to play a bit with those tags what fit the best .. .
Ocean West Posted April 25, 2015 Author Posted April 25, 2015 here is my results http://fmforums.com/advertisersalso added the rand() option back in for the ORDER each time the page loads they are in a random order
不中用 Posted April 25, 2015 Posted April 25, 2015 .If your ad_;location in your ads are all set with the same name fmf_square .. can't you not just use 'ad_location="fmf_square" and ad_active=1' (even with double quotes, it does work for me) .. those slashes before single quote should be fine too I guess .. .
不中用 Posted April 25, 2015 Posted April 25, 2015 here is my results http://fmforums.com/advertisersalso added the rand() option back in for the ORDER each time the page loads they are in a random order . I don't see anything as guest .. maybe you switched it off in your permissions ? .
Ocean West Posted April 25, 2015 Author Posted April 25, 2015 http://fmforums.com/advertisers/ try now
不中用 Posted April 25, 2015 Posted April 25, 2015 http://fmforums.com/advertisers/ try now . This is the only thing I see .. .
Ocean West Posted April 25, 2015 Author Posted April 25, 2015 not sure whats up with permissions... - is it on the right side bar http://fmforums.com ?
不中用 Posted April 25, 2015 Posted April 25, 2015 not sure whats up with permissions... - is it on the right side bar http://fmforums.com ? . .
newbie LAC Posted April 25, 2015 Posted April 25, 2015 . This is the only thing I see .. . AdBlock?
不中用 Posted April 25, 2015 Posted April 25, 2015 AdBlock?.Will crawl under a stone somewhere now .. yes .. adblock .. .
Recommended Posts
Archived
This topic is now archived and is closed to further replies.