Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> WYbranie losowej liczby
sajborg
post
Post #1





Grupa: Zarejestrowani
Postów: 271
Pomógł: 0
Dołączył: 20.08.2003
Skąd: Szczecinek

Ostrzeżenie: (0%)
-----


Siemka zrobilem sobie takie rotator banerów

[php:1:8f2a22e3e7]<?php
$sql="SELECT * FROM homp_baner";
$result=$db->sql_query($sql);
$ile=0;
$res2=$db->sql_fetchrow($result);
$od=$res2['baner_id'];
while ($res=$db->sql_fetchrow($result)){
$ile=$res['baner_id'];
}
function baner ($typ){
global $db,$ile,$od;
$losowy=rand($od,$ile);
$sql="SELECT * FROM homp_baner WHERE baner_id='".$losowy."' AND baner_rozm='".$typ."'";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Nie mogę wyswietlić Banera.", "", __LINE__, __FILE__, $sql);
}
$baner=$db->sql_fetchrow($result);
if ($baner['baner_show']==$baner['baner_max_show']){
baner($typ);
}else{
if ($baner['baner_typ']=='FLASH'){
echo $baner['baner_flash'];
$sql="UPDATE homp_baner SET baner_show=baner_show+1 WHERE baner_id='".$losowy."'";
$db->sql_query($sql);
}else{
echo '<a href="'.$baner['baner_url'].'" target=_top><img src="'.$baner['baner_img'].'" border="0" alt="'.$baner['baner_alt'].'" width="400" height="50"></a>';
$sql="UPDATE homp_baner SET baner_show=baner_show+1 WHERE baner_id='".$losowy."'";
$db->sql_query($sql);
}
}
}

?>[/php:1:8f2a22e3e7]
Ale u mnie nie zdaje egzaminu :)Poniewą najpierw losuje liczbe a potem dopiero pobieram baner.I jesli wylosowana loczba nie spełnia kryteriów baner nie zostaje pokazany.Chciałem to zrobic inaczej mianowicie.Pobieram wszystko idy banerów które spełniają kryterium a potem z tych liczba losuje jakąś.Ale nie wiem jak wylosowąc jakąś liczbe z kilkunastu podanych (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sajborg
post
Post #2





Grupa: Zarejestrowani
Postów: 271
Pomógł: 0
Dołączył: 20.08.2003
Skąd: Szczecinek

Ostrzeżenie: (0%)
-----


Kurde coś mi nie gra mam tak

[php:1:7003eff862]<?php
function baner ($typ){
global $db;
$id=array();
$sql="SELECT * FROM homp_baner WHERE baner_rozm=".$typ."";
$result=$db->sql_query($sql);
while ($idy=$db->sql_fetchrow($result)){
$id[]=$idy['baner_id'];
}
$losowy=array_rand($id,1);
$sql="SELECT * FROM homp_baner WHERE baner_id='".$losowy."' AND baner_rozm='".$typ."'";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Nie mogę wyswietlić Banera.", "", __LINE__, __FILE__, $sql);
}
$baner=$db->sql_fetchrow($result);
if ($baner['baner_show']==$baner['baner_max_show']){

}else{
if ($baner['baner_typ']=='FLASH'){
echo $baner['baner_flash'];
$sql="UPDATE homp_baner SET baner_show=baner_show+1 WHERE baner_id='".$losowy."'";
$db->sql_query($sql);
}else{
echo '<a href="'.$baner['baner_url'].'" target=_top><img src="'.$baner['baner_img'].'" border="0" alt="'.$baner['baner_alt'].'" width="400" height="50"></a>';
$sql="UPDATE homp_baner SET baner_show=baner_show+1 WHERE baner_id='".$losowy."'";
$db->sql_query($sql);
}
}
}
?>[/php:1:7003eff862]

I pokazuje mi sie taki błąd

Kod
Warning: array_rand() [function.array-rand]: Second argument has to be between 1 and the number of elements in the array in g:wwwphpbb.netfunction.php on line 10
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.09.2025 - 07:56