raivis Posted October 16, 2006 Report Share Posted October 16, 2006 Veelos uzkodeet dinamisku menu, bet netieku ar sho to skaidriibaa. Ljoti ceru, ka jums radiisies kaadi priekshlikumi. Failaa menu.txt katraa rindaa tiek pieshkjirti atshkjiriigi mainiigo veertiibas. Kaa lai iestatu, lai tiktu izprinteeti visu mainiigo veertiibas, bet briidii, kad mainiigaa veertiiba tiks nodefineeta adresee piem. code.php?menu=894, attieciigaas rindas attieciigajam mainiigajam buus piem. pieshkjirts bold teksta stils? Tas izskatiitos shaadi: ja code.php?menu=232, tad echo Welcome Message Contacts ----------- turklaat, ja code.php?menu=014, tad echo Welcome Message Contacts ----------- utt. Koda iesaakums izskataas: /* menu.txt --------------- */ 014|Welcome| 232|Message| 894|Contacts| /* code.php --------------- */ $lines = file("menu.txt"); $menuList = array(); $i = 1; foreach ($lines as $row){ list($a_href,$name) = explode('|', $row); $menuList[] = array('id'=>$id, 'name'=>$name); $i++; } foreach ($menuList as $key => $info){ if ($id == $info['id']){ $echo_menu2 = "<div class=\"active\">".$info['name']."</div>"; foreach($lines as $line_num => $line){ list($a_href,$name)=explode('|', $line); if(isset($echo_menu2)){$echo_menu=$echo_menu2;} $echo_menu = <<<HTML <a href="?menu=$id">$name</a><br> HTML; } } } echo $echo_menu; Link to comment Share on other sites More sharing options...
bubu Posted October 16, 2006 Report Share Posted October 16, 2006 Uzrakstīšu domu: if ($_GET masīvā ir id no tā faila) { drukāt boldā } else { drukāt parastu } Ceru, ka pats tālāk izdomāsi. Link to comment Share on other sites More sharing options...
raivis Posted October 16, 2006 Author Report Share Posted October 16, 2006 (edited) Nevajag taisīt muļķīgas QUOTEs (bubu) Piedod, programmeeshanaa esmu veel tikai lietprateejs. Taadeelj buutu ljoti jauki, ja tu tomeer vareetu man nodefineet pilnu paraugu. Paldies! Piem. nenostraadaa metode: foreach($lines as $line_num => $line){ list($a_href,$name,$sourche)=explode('|', $line); if(isset($echo_menu2)){$echo_menu=$echo_menu2;} if($_GET['id']=$a_href){ echo "<div class=\"active\">$name</div>"; }else{ echo "<li><a href=\"?id=$a_href\">$name</a></li>"; } } Edited October 17, 2006 by bubu Link to comment Share on other sites More sharing options...
andrisp Posted October 17, 2006 Report Share Posted October 17, 2006 (edited) Pāšā kodā neiedziļinājos, bet salīdzināšanu veic ar == nevis =.. Šeit skaties vairāk -> http://lv2.php.net/manual/en/language.oper...comparison.php.. ... if($_GET['id'] == $a_href){ ... Piedod, programmeeshanaa esmu veel tikai lietprateejs. Ko tad nezini tādas elementāras lietas ? =) Edited October 17, 2006 by andrisp Link to comment Share on other sites More sharing options...
bubu Posted October 17, 2006 Report Share Posted October 17, 2006 lietpratējs taču nozīmē tādu, kurš labi māk savu darāmo!? Link to comment Share on other sites More sharing options...
blackhalt Posted October 17, 2006 Report Share Posted October 17, 2006 <?php $a=file('menu.txt'); foreach($a as $b) { $c=explode('|',$b); $d=trim($c[0]); if($_GET['menu']==$d){ echo '<strong>'.$c[1].'</strong><br />'; }else{ echo $c[1].'<br />'; } } ?> Link to comment Share on other sites More sharing options...
raivis Posted October 18, 2006 Author Report Share Posted October 18, 2006 Paldies, kaa reizeem gadaas - nepiefikseeju siiku kljuudu, kur = vietaa buutu jaabuut == nostraadaa ar if($_GET['id']==$a_href){... Link to comment Share on other sites More sharing options...
Recommended Posts