Sasa Posted April 28, 2008 Report Share Posted April 28, 2008 <TD id=fig_det_holder> <IMG id=Image0 style="Z-INDEX: 1" tabIndex=15 src="http://192.168.0.164/Images/figuralas_detalas/_blank.gif"> </TD> kā lai es tanī tabulas ailītē randomā varētu ielikt bildi kuras man būtu kaut kur augstāk aprakstītas? Link to comment Share on other sites More sharing options...
Evi Posted April 28, 2008 Report Share Posted April 28, 2008 Atrast googlee kaadu piemeeru un censties saprast kaa tas darbojas. Link to comment Share on other sites More sharing options...
bubu Posted April 28, 2008 Report Share Posted April 28, 2008 Nekādas maģijas tur nav. Apraksti bildes: $bildes = array("bilde1.png", "bilde2.jpg", ...); Un randomā paņem kādu: echo $bildes[array_rand($bildes)]; Galvenais - neaizmirsti RTFM: http://lv.php.net/array_rand http://lv.php.net/rand Link to comment Share on other sites More sharing options...
Evi Posted April 28, 2008 Report Share Posted April 28, 2008 Nebij JS domaats? :) Link to comment Share on other sites More sharing options...
bubu Posted April 28, 2008 Report Share Posted April 28, 2008 Uff, sorry, nepastījos sadaļu. Nekas principā īpaši savādāks tāpat nav; var bildes = ["bilde1.png", "bilde2.jpg"], ...; alert(bildes[Math.floor(Math.random()*bildes.length)]); http://developer.mozilla.org/en/docs/Core_...cts:Math:random http://developer.mozilla.org/en/docs/Core_...ects:Math:floor Link to comment Share on other sites More sharing options...
Sasa Posted April 28, 2008 Author Report Share Posted April 28, 2008 sataisīju šādi: var img_name = new Array(3); img_name[1] = "http://192.168.0.164/web_kat/temp_kat/Images/_blank1.jpg"; img_name[2] = "http://192.168.0.164/web_kat/temp_kat/Images/_blank2.jpg"; img_name[3] = "http://192.168.0.164/web_kat/temp_kat/Images/_blank3.jpg"; var l = img_name.length; var rnd_no = Math.floor(l*Math.random()); document.getElementById("Image0").src = img_name[rnd_no]; bet man brīžiem parādās undefined ... kapē tā? it kā viss ir ok! Link to comment Share on other sites More sharing options...
Mikijs Posted April 28, 2008 Report Share Posted April 28, 2008 (edited) labakais veids ka so dairt.. - LOTI LABS PIEMERS Bildes atrodas faila .lv/images/ PHP atrodas faila .lv/images/ taisam <img src='images/fails.php' border='0' width='190'> Tagad mums inkludo bildi 1 kura bus tip 190 pec width tapec bus mazinja tos izmerus pats vari salikt - Bildes piemers: http://www.teiksmina.lv/images/news/rotators.php - PHP saturs: http://paste.php.lv/7251/nonum Edited April 28, 2008 by Mikijs Link to comment Share on other sites More sharing options...
Sasa Posted April 28, 2008 Author Report Share Posted April 28, 2008 Mikijs tu vispār skaties kurā sadāļā es šo ierakstīu ! :x man tavs PHP piemērs neder! Link to comment Share on other sites More sharing options...
bubu Posted April 28, 2008 Report Share Posted April 28, 2008 bet man brīžiem parādās undefined ... kapē tā? it kā viss ir ok! Tāpēc, ka masīva indeksi sākas no 0 nevis no 1. Nerakti to new Array sintaksi. Pats redzi, cik viegli nokļūdīties. Raksti vienkāršāk: var img_name = [ "http://192.168.0.164/web_kat/temp_kat/Images/_blank1.jpg", "http://192.168.0.164/web_kat/temp_kat/Images/_blank2.jpg", "http://192.168.0.164/web_kat/temp_kat/Images/_blank3.jpg"]; Vai vēl labāk - ja tev visi nosaukumi ir _blankXX.jpg formā, tad vispār nafig masīvs vajadzīgs... var max_num = 10; // bilžu numuri no 1 līdz 10 ieskaitot var rnd = Math.floor(max_num*Math.random())+1; document.getElementById("Image0").src = "http://192.168.0.164/web_kat/temp_kat/Images/_blank" + rnd + ".jpg"; Link to comment Share on other sites More sharing options...
andrisp Posted April 28, 2008 Report Share Posted April 28, 2008 Mikij, tavs kods man liekas vispār nav saistīts ar autora definēto problēmu. Un ja arī būtu, neredzu iemeslu kāpēc, lai tas būtu "LOTI LABS PIEMERS". Vai arī atkal kaut kur nozagi un uzdodot par savu, gribi nomētotā kruto koderi ? :] Link to comment Share on other sites More sharing options...
bubu Posted April 28, 2008 Report Share Posted April 28, 2008 Atlika tik gūglē ierakstīt vienu rindiņu no Mikija koda: "$imageInfo = pathinfo($_GET['img']);" un lūk rezultāts: http://boingboing.net/busted_tees/rotate.php Link to comment Share on other sites More sharing options...
Recommended Posts