PDA

View Full Version : ایجاد منوی داینامیک با php



.fatemeh
جمعه 03 دی 1389, 13:06 عصر
سلام
من داخل سایتم منو و زیر منو می خوام بزارم که باید از بانک بیان و نمایش داده بشن.
که فکر کنم باید از جاوا و php استفاده کنم.
من کدش رو نوشتم و از حلقه for استفاده کردم که وقتی موس روی یکی از submenu ها می ره id مربوط به submenu رو بگیره و زیر منوها رو بر اساس اون از بانک بیاره.
اما فقط آخرین id رو می گیره.
از آرایه هم نمی تونم استفاده کنم.
لطفا راهنمایی کنین.
ممنون

mohsen6500
جمعه 03 دی 1389, 15:09 عصر
لطفا کدتو به صورت کامل بذار تا ببینیم چی هست؟
بعدش میشه رو ش کار کرد

.fatemeh
جمعه 03 دی 1389, 16:23 عصر
<html><head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<link rel="stylesheet" type="text/css" href="ddsmoothmenu.css" />
<link rel="stylesheet" type="text/css" href="ddsmoothmenu-v.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="ddsmoothmenu.js">

</script>

<script type="text/javascript">


ddsmoothmenu.init({
mainmenuid: "smoothmenu2", //Menu DIV id
orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
//customtheme: ["#804000", "#482400"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

</script>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>

<div id="smoothmenu2" class="ddsmoothmenu-v">
<ul>
<li>
<?php
$q="select * from section";
$re=mysql_query($q);
$num=mysql_num_rows($re);
for($i=0;$i<$num;$i++)
{
$f=mysql_fetch_array($re);?>
<div><a href="untitled1.php "><?php echo $f['name'];?></a></div>
<?php }?>
<ul>
<li>
<?php

$q1="SELECT * FROM `category` WHERE id_s=";
$re1=mysql_query($q1);
$num1=mysql_num_rows($re1);
for($i=0;$i<$num1;$i++)
{
$f1=mysql_fetch_array($re1); ?>
<a href="untitled1.php?id1=<?php echo $f1['id_c'];?>"> <?php echo $f1['name'];?></a>
<?php }?>
<ul>
<li>
<?php

$q2="SELECT * FROM `group` WHERE id_c=";
$re2=mysql_query($q2);
$num2=mysql_num_rows($re2);
for($i=0;$i<$num2;$i++)
{
$f2=mysql_fetch_array($re2);?>


<a href="untitled1.php?id=<?php $f2['id_g'];?>"> <?php echo $f2['name'];?></a>
<?php }?>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<br style="clear: right" />
</div>
</body>
</html>

دو تا فایل هم هست یکی css و یکی هم جاوا که ابتدای کد فراخوانی شدند.
جاوا:


var ddsmoothmenu={

//Specify full URL to down and right arrow images (23 is padding-right added to top level LIs with drop downs):
arrowimages: {down:['downarrowclass', 'down.gif', 23], right:['rightarrowclass', 'right.gif']},
transition: {overtime:300, outtime:300}, //duration of slide in/ out animation, in milliseconds
shadow: {enable:true, offsetx:5, offsety:5}, //enable shadow?
showhidedelay: {showdelay: 100, hidedelay: 200}, //set delay in milliseconds before sub menus appear and disappear, respectively

///////Stop configuring beyond here///////////////////////////

detectwebkit: navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1, //detect WebKit browsers (Safari, Chrome etc)
detectie6: document.all && !window.XMLHttpRequest,
css3support: window.msPerformance || (!document.all && document.querySelector), //detect browsers that support CSS3 box shadows (ie9+ or FF3.5+, Safari3+, Chrome etc)

getajaxmenu:function($, setting){ //function to fetch external page containing the panel DIVs
var $menucontainer=$('#'+setting.contentsource[0]) //reference empty div on page that will hold menu
$menucontainer.html("Loading Menu...")
$.ajax({
url: setting.contentsource[1], //path to external menu file
async: true,
error:function(ajaxrequest){
$menucontainer.html('Error fetching content. Server Response: '+ajaxrequest.responseText)
},
success:function(content){
$menucontainer.html(content)
ddsmoothmenu.buildmenu($, setting)
}
})
},


buildmenu:function($, setting){
var smoothmenu=ddsmoothmenu
var $mainmenu=$("#"+setting.mainmenuid+">ul") //reference main menu UL
$mainmenu.parent().get(0).className=setting.classn ame || "ddsmoothmenu"
var $headers=$mainmenu.find("ul").parent()
$headers.hover(
function(e){
$(this).children('a:eq(0)').addClass('selected')
},
function(e){
$(this).children('a:eq(0)').removeClass('selected' )
}
)
$headers.each(function(i){ //loop through each LI header
var $curobj=$(this).css({zIndex: 100-i}) //reference current LI header
var $subul=$(this).find('ul:eq(0)').css({display:'bloc k'})
$subul.data('timers', {})
this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
this.istopheader=$curobj.parents("ul").length==1? true : false //is top level header?
$subul.css({top:this.istopheader && setting.orientation!='v'? this._dimensions.h+"px" : 0})
$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: smoothmenu.arrowimages.down[2]} : {}).append( //add arrow images
'<img src="'+ (this.istopheader && setting.orientation!='v'? smoothmenu.arrowimages.down[1] : smoothmenu.arrowimages.right[1])
+'" class="' + (this.istopheader && setting.orientation!='v'? smoothmenu.arrowimages.down[0] : smoothmenu.arrowimages.right[0])
+ '" style="border:0;" />'
)
if (smoothmenu.shadow.enable && !smoothmenu.css3support){ //if shadows enabled and browser doesn't support CSS3 box shadows
this._shadowoffset={x:(this.istopheader?$subul.off set().left+smoothmenu.shadow.offsetx : this._dimensions.w), y:(this.istopheader? $subul.offset().top+smoothmenu.shadow.offsety : $curobj.position().top)} //store this shadow's offsets
if (this.istopheader)
$parentshadow=$(document.body)
else{
var $parentLi=$curobj.parents("li:eq(0)")
$parentshadow=$parentLi.get(0).$shadow
}
this.$shadow=$('<div class="ddshadow'+(this.istopheader? ' toplevelshadow' : '')+'"></div>').prependTo($parentshadow).css({left:this._shadow offset.x+'px', top:this._shadowoffset.y+'px'}) //insert shadow DIV and set it to parent node for the next shadow div
}
$curobj.hover(
function(e){
var $targetul=$subul //reference UL to reveal
var header=$curobj.get(0) //reference header LI as DOM object
clearTimeout($targetul.data('timers').hidetimer)
$targetul.data('timers').showtimer=setTimeout(func tion(){
header._offsets={left:$curobj.offset().left, top:$curobj.offset().top}
var menuleft=header.istopheader && setting.orientation!='v'? 0 : header._dimensions.w
menuleft=(header._offsets.left+menuleft+header._di mensions.subulw>$(window).width())? (header.istopheader && setting.orientation!='v'? -header._dimensions.subulw+header._dimensions.w : -header._dimensions.w) : menuleft //calculate this sub menu's offsets from its parent
if ($targetul.queue().length<=1){ //if 1 or less queued animations
$targetul.css({left:menuleft+"px", width:header._dimensions.subulw+'px'}).animate({he ight:'show',opacity:'show'}, ddsmoothmenu.transition.overtime)
if (smoothmenu.shadow.enable && !smoothmenu.css3support){
var shadowleft=header.istopheader? $targetul.offset().left+ddsmoothmenu.shadow.offset x : menuleft
var shadowtop=header.istopheader?$targetul.offset().to p+smoothmenu.shadow.offsety : header._shadowoffset.y
if (!header.istopheader && ddsmoothmenu.detectwebkit){ //in WebKit browsers, restore shadow's opacity to full
header.$shadow.css({opacity:1})
}
header.$shadow.css({overflow:'', width:header._dimensions.subulw+'px', left:shadowleft+'px', top:shadowtop+'px'}).animate({height:header._dimen sions.subulh+'px'}, ddsmoothmenu.transition.overtime)
}
}
}, ddsmoothmenu.showhidedelay.showdelay)
},
function(e){
var $targetul=$subul
var header=$curobj.get(0)
clearTimeout($targetul.data('timers').showtimer)
$targetul.data('timers').hidetimer=setTimeout(func tion(){
$targetul.animate({height:'hide', opacity:'hide'}, ddsmoothmenu.transition.outtime)
if (smoothmenu.shadow.enable && !smoothmenu.css3support){
if (ddsmoothmenu.detectwebkit){ //in WebKit browsers, set first child shadow's opacity to 0, as "overflow:hidden" doesn't work in them
header.$shadow.children('div:eq(0)').css({opacity: 0})
}
header.$shadow.css({overflow:'hidden'}).animate({h eight:0}, ddsmoothmenu.transition.outtime)
}
}, ddsmoothmenu.showhidedelay.hidedelay)
}
) //end hover
}) //end $headers.each()
if (smoothmenu.shadow.enable && smoothmenu.css3support){ //if shadows enabled and browser supports CSS3 shadows
var $toplevelul=$('#'+setting.mainmenuid+' ul li ul')
var css3shadow=parseInt(smoothmenu.shadow.offsetx)+"px "+parseInt(smoothmenu.shadow.offsety)+"px 5px #aaa" //construct CSS3 box-shadow value
var shadowprop=["boxShadow", "MozBoxShadow", "WebkitBoxShadow", "MsBoxShadow"] //possible vendor specific CSS3 shadow properties
for (var i=0; i<shadowprop.length; i++){
$toplevelul.css(shadowprop[i], css3shadow)
}
}
$mainmenu.find("ul").css({display:'none', visibility:'visible'})
},

init:function(setting){
if (typeof setting.customtheme=="object" && setting.customtheme.length==2){ //override default menu colors (default/hover) with custom set?
var mainmenuid='#'+setting.mainmenuid
var mainselector=(setting.orientation=="v")? mainmenuid : mainmenuid+', '+mainmenuid
document.write('<style type="text/css">\n'
+mainselector+' ul li a {background:'+setting.customtheme[0]+';}\n'
+mainmenuid+' ul li a:hover {background:'+setting.customtheme[1]+';}\n'
+'</style>')
}
this.shadow.enable=(document.all && !window.XMLHttpRequest)? false : this.shadow.enable //in IE6, always disable shadow
jQuery(document).ready(function($){ //ajax menu?
if (typeof setting.contentsource=="object"){ //if external ajax menu
ddsmoothmenu.getajaxmenu($, setting)
}
else{ //else if markup menu
ddsmoothmenu.buildmenu($, setting)
}
})
}

} //end ddsmoothmenu variable

mohsen6500
جمعه 03 دی 1389, 19:17 عصر
mysql_fetch_array($re)

سلام چرا از assoc استفاده نکردی؟


mysql_fetch_assoc

با این امتحان کن
احتمال زیاد درست میشه

.fatemeh
جمعه 03 دی 1389, 19:40 عصر
امتحان می کنم
ولی این دو تا چه فرقی با هم دارند؟

UnnamE
جمعه 03 دی 1389, 20:18 عصر
زياد ربطي به سوال شما نداره ولي چرا اين همه از جاوا استفاده كردي
در صورتي كه ميشه بيشتر اين بار ايجاد منوهاي تو در تو رو به گردن ‍CSS انداخت و جاوا اسكريپت خلي خيلي كمتري نوشت

.fatemeh
جمعه 03 دی 1389, 20:35 عصر
من خودم به جاوا مسلط نیستم و این کد جاوا رو از اینترنت گرفتم.
اگر با css کدشو دارین که کار می کنه برام بزارین لطفا

.fatemeh
جمعه 03 دی 1389, 20:46 عصر
سلام چرا از assoc استفاده نکردی؟
امتحان کردم، درست نشد:ناراحت:
هنوزم مشکلم اینه که چطوری وقتی موس روی submenu می ره، چند تا id رو بگیرم؛ در صورتی که صفحه رفرش نمی شه؟!!!

Mr.Moghadam
جمعه 03 دی 1389, 23:41 عصر
من خودم به جاوا مسلط نیستم و این کد جاوا رو از اینترنت گرفتم.
اگر با css کدشو دارین که کار می کنه برام بزارین لطفا

http://www.cssdrive.com/index.php/examples/exampleitem/css_drop_down_menu/

این یک منو با css که برای اینکه خوشکلترش کنی باید بیشتر روش کار کنی.

موفق باشی