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
https://forums.phpfreaks.com/topic/156994-solved-is-this-possible-inside-a-loop/
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;

 

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.

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">';}

	  ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.