Jump to content

[SOLVED] is this possible inside a loop?


chipmunken

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.