Ispis baze s oglasima

Glup naslov posta

ovo mi je ispis iz baze

sada bi trebao da između svako 3 ili 4 reda ispise google oglas link

može malo pomoći

može li drukčije

može…

zašto drukčije? Antelaca ti je dao odlično rješenje.

Napravi sam antelaca Hvala

<span class="syntaxhtml"><br /><span class="syntaxdefault"><?php&nbsp;<br /><br /></span><span class="syntaxkeyword">function&nbsp;</span><span class="syntaxdefault">voliMeNeVoliMe</span><span class="syntaxkeyword">(){<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">);<br />}<br /><br />function&nbsp;</span><span class="syntaxdefault">ajUbaci</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$odakle</span><span class="syntaxkeyword">){<br />&nbsp;&nbsp;&nbsp;&nbsp;switch(</span><span class="syntaxdefault">$odakle</span><span class="syntaxkeyword">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span class="syntaxstring">'izDatoteke'</span><span class="syntaxkeyword">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">izvadiIzDatoteke</span><span class="syntaxkeyword">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span class="syntaxstring">'izBaze'</span><span class="syntaxkeyword">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">izvadiIzBaze</span><span class="syntaxkeyword">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span class="syntaxstring">'mislin&nbsp;da&nbsp;si&nbsp;se&nbsp;sjeba&nbsp;s&nbsp;tim&nbsp;'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$odakle</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'!&nbsp;moguce&nbsp;varijante&nbsp;su&nbsp;izDatoteke&nbsp;ili&nbsp;izBaze'</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br />function&nbsp;</span><span class="syntaxdefault">izvadiIzDatoteke</span><span class="syntaxkeyword">(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!</span><span class="syntaxdefault">file_exists</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'oglasi.txt'</span><span class="syntaxkeyword">))&nbsp;die(</span><span class="syntaxstring">'moras&nbsp;napraviti&nbsp;datoteku&nbsp;oglasi.txt&nbsp;i&nbsp;u&nbsp;nju&nbsp;ubaciti&nbsp;oglase&nbsp;odvojene&nbsp;":)"'</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">$oglasi&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">explode</span><span class="syntaxkeyword">(</span><span class="syntaxstring">":)"</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">file_get_contents</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'oglasi.txt'</span><span class="syntaxkeyword">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">$oglasi</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">rand</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">count</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$oglasi</span><span class="syntaxkeyword">)-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">)];<br />}<br /><br />function&nbsp;</span><span class="syntaxdefault">izvadiIzBaze</span><span class="syntaxkeyword">(){<br /></span><span class="syntaxcomment">/*<br />valjda&nbsp;si&nbsp;vec&nbsp;spojen&nbsp;na&nbsp;bazu...&nbsp;pa&nbsp;bi&nbsp;ovo&nbsp;izgledalo&nbsp;ovako&nbsp;nekako<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;$rez&nbsp;=&nbsp;mysql_query("select&nbsp;oglas&nbsp;from&nbsp;oglasi&nbsp;order&nbsp;by&nbsp;rand()&nbsp;limit&nbsp;1")&nbsp;or&nbsp;die(mysql_error());<br />&nbsp;&nbsp;&nbsp;&nbsp;$row&nbsp;=&nbsp;mysql_fetch_array($rez);<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$row['oglas'];<br />*/<br /></span><span class="syntaxkeyword">}<br /><br />function&nbsp;</span><span class="syntaxdefault">ubacitiIliNe</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$brojOglasa</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$vaseZelje</span><span class="syntaxkeyword">=</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">$dodatneZelje</span><span class="syntaxkeyword">=</span><span class="syntaxstring">'izDatoteke'</span><span class="syntaxkeyword">){<br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span class="syntaxdefault">$vaseZelje</span><span class="syntaxkeyword">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">//&nbsp;da,da&nbsp;ispunjavam&nbsp;i&nbsp;zelje<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">if(</span><span class="syntaxdefault">is_string</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$vaseZelje</span><span class="syntaxkeyword">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(</span><span class="syntaxdefault">$vaseZelje</span><span class="syntaxkeyword">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span class="syntaxstring">'svaki_treci'</span><span class="syntaxkeyword">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span class="syntaxdefault">$brojOglasa&nbsp;</span><span class="syntaxkeyword">%&nbsp;</span><span class="syntaxdefault">3&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">)&nbsp;return&nbsp;</span><span class="syntaxdefault">ajUbaci</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dodatneZelje</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span class="syntaxstring">'svaki_cetvrti'</span><span class="syntaxkeyword">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span class="syntaxdefault">$brojOglasa&nbsp;</span><span class="syntaxkeyword">%&nbsp;</span><span class="syntaxdefault">4&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">)&nbsp;return&nbsp;</span><span class="syntaxdefault">ajUbaci</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dodatneZelje</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span class="syntaxstring">'slusaj..&nbsp;&nbsp;<strong>'</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">$vaseZelje</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'</strong>...&nbsp;to&nbsp;ne&nbsp;moze!'</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span class="syntaxdefault">$brojOglasa&nbsp;</span><span class="syntaxkeyword">%&nbsp;</span><span class="syntaxdefault">$vaseZelje&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">)&nbsp;return&nbsp;</span><span class="syntaxdefault">ajUbaci</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dodatneZelje</span><span class="syntaxkeyword">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}else{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">//&nbsp;kad&nbsp;vec&nbsp;ti&nbsp;nemas&nbsp;pojima&nbsp;sta&nbsp;oces...<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">return&nbsp;</span><span class="syntaxdefault">$ocemoLi&nbsp;</span><span class="syntaxkeyword">=&nbsp;(</span><span class="syntaxdefault">voliMeNeVoliMe</span><span class="syntaxkeyword">())&nbsp;?&nbsp;</span><span class="syntaxdefault">ajUbaci</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$dodatneZelje</span><span class="syntaxkeyword">)&nbsp;:&nbsp;</span><span class="syntaxstring">''</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /><br /><br /><br /><br /></span><span class="syntaxdefault">$i&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">;<br />while(</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword"><=</span><span class="syntaxdefault">10</span><span class="syntaxkeyword">){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">.</span><span class="syntaxstring">'<br />'</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span class="syntaxdefault">ubacitiIliNe</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">).</span><span class="syntaxstring">'<br />'</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">$i</span><span class="syntaxkeyword">++;<br />}<br /><br /></span><span class="syntaxcomment">/*<br /><br />kako&nbsp;ovo&nbsp;radi?&nbsp;<br /><br />kad&nbsp;pozivas&nbsp;funkciju&nbsp;ubacitiIliNe()&nbsp;obavezan&nbsp;je&nbsp;samo&nbsp;prvi&nbsp;parametar&nbsp;a&nbsp;to&nbsp;je&nbsp;broj&nbsp;oglasa.<br />ako&nbsp;je&nbsp;naveden&nbsp;samo&nbsp;parametar&nbsp;$brojOglasa,&nbsp;oglasi&nbsp;se&nbsp;vade&nbsp;iz&nbsp;datoteke&nbsp;oglasi.txt&nbsp;i&nbsp;funkcija&nbsp;sama&nbsp;odredjiva&nbsp;oce&nbsp;li&nbsp;ispisati&nbsp;oglas&nbsp;ili&nbsp;ne&nbsp;nakon&nbsp;svakog&nbsp;oglasa.<br /><br />drugi&nbsp;parametar&nbsp;oznacava&nbsp;nakon&nbsp;koliko&nbsp;ispisa&nbsp;ubacivas&nbsp;oglas<br /><br />moguce&nbsp;varijante<br /><br />ubacitiIliNe($brojOglasa,5);<br />ubacitiIliNe($brojOglasa,'svaki_treci');<br />ubacitiIliNe($brojOglasa,'svaki_cetvrti');<br /><br /><br />treci&nbsp;parametar&nbsp;je&nbsp;odakle&nbsp;vuces&nbsp;oglase,&nbsp;iz&nbsp;baze&nbsp;ili&nbsp;datoteke,&nbsp;po&nbsp;defaultu&nbsp;je&nbsp;izDatoteke<br /><br />primjer<br /><br />ubacitiIliNe($brojOglasa,'svaki_cetvrti','izBaze');<br /><br /><br />Zakljucak:&nbsp;ovo&nbsp;je&nbsp;debilan&nbsp;kod&nbsp;koji&nbsp;radi&nbsp;ono&nbsp;sta&nbsp;zelis&nbsp;i&nbsp;kad&nbsp;nemas&nbsp;pojma&nbsp;sta&nbsp;zelis<br /><br />cemu&nbsp;komplicirati?<br /><br />*/<br /></span><span class="syntaxdefault">?><br /></span><br /></span>

oglasi.txt

[HTML]
:slight_smile:
:slight_smile:
:slight_smile:
:slight_smile:
:slight_smile:
:slight_smile:

[/HTML]

bolje?

Puno hvala još jednom


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja