chipmunken Posted May 5, 2009 Share Posted May 5, 2009 I have dynamic menu on my site that gets catagoris and products from DB. But my boss decided that he wants the image to change so it looks highlighted. Like this *Menu1 -Menu2 *Menu3 *Menu4 Note Meny2 is pressed and infront of the link I have an image. If array value == the _GET variabel then I want it to use another image. I know its possible with if statments inside a while loop but I just cant figure out how to get this to work. I have tried a foreach statment with no success.. <? $sub=$_GET['sub']; $pil1 = 'box_3-03.png'; $pil2 = 'box_3-03_2.png'; // loop that builds the menu block while($menyrows=mysql_fetch_array($meny)){ ?> <table border="0"> <tr> <td> <img src="images/box_3/<? if ($sub == $menyrows['kat']) { echo $pil2; } echo $pil1; ?>" height="10" width="10" alt="" /></td> <td width="129" height="7" background="ximages/box_4/box_marked.png"> <!----> <a href="?lang=en&sec=products&sub=<? echo $menyrows['kat']; ?>" target="_self"> <div style="color:#<? echo $text1; ?>"> <? echo $menyrows['kat']; ?></div> </a></td> </tr> <tr> <td></td> <td align="left"> <? if ($sub == $menyrows['kat']){ while($rows=mysql_fetch_array($result)){ ?> <div style="font-size:9px"> <a href="?lang=en&sec=products&sub=<? echo $sub; ?>&info=<? echo $rows['id_contact']; ?>"><? echo $rows['product']; ?></a></div> <? } } ?> </td> </tr> </table> <? } // end of loop block menu ?> Link to comment https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/ Share on other sites More sharing options...
revraz Posted May 5, 2009 Share Posted May 5, 2009 Use CSS to display it differently. Link to comment https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/#findComment-827018 Share on other sites More sharing options...
chipmunken Posted May 5, 2009 Author Share Posted May 5, 2009 Is this what you hade in mind? syntax not correct ofc its just a copy past model of what I think you ment. This is the best I can come up with at this hour. Kinda late so ill check if I understand it better tomorrow a { border:0; color:#555; text-decoration:none; background-image: url('something.gif'); background-repeat: no-repeat; background-attachment:fixed; background-position: 50px 100px; } a:activ{ color:#000; text-decoration:none; background-image: url('something_else.gif'); background-repeat: no-repeat; background-attachment:fixed; background-position: 50px 100px; Link to comment https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/#findComment-827026 Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 You probably want to give that background image a height and width. But you also don't want it in the A tag. Perhaps a DIV? Link to comment https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/#findComment-827045 Share on other sites More sharing options...
chipmunken Posted May 6, 2009 Author Share Posted May 6, 2009 Both of you suggest CSS but how to identify the link in css? Without changeing all of the images? When I click link[1] it send's a value in address field witch is uniqe. So I figure that if $sub == $menyrows['kat'] then change pic. You dont need to write the code but a more detailed explanation woulde be awsome. Or a link in the right direction link[1] link[2] link[3] I still need an if statment of some kind. It was all easy when I only hade 4 catagoris and the products under them was from databas. Now when the catagories also come from DB I cant get my head around identifying witch array value is clicked. Link to comment https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/#findComment-827401 Share on other sites More sharing options...
chipmunken Posted May 6, 2009 Author Share Posted May 6, 2009 Solved problem without CSS I knew it whoulde be possible with only php. I forgot about else haha Well here is the code that made it all happen. <? if ($sub == $menyrows['kat']){ echo '<img src="/images/box_3/' . $pil2 . '" alt="" border="0">'; } else {echo '<img src="/images/box_3/' . $pil1 . '" alt="" border="0">';} ?> Link to comment https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/#findComment-827451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.