Incorporating a Javascript with PHP in a menu-

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
suzithepid
Forum Newbie
Posts: 3
Joined: Wed Aug 01, 2007 10:56 am

Incorporating a Javascript with PHP in a menu-

Post by suzithepid »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have created a menu which, when linked with a javascript, displays a logo off to the side of the link. I can get it to display only the first image in the database. I am certain it's a simple fix, but I am too close to it now and am unable to see my error. I would appreciate assistance to get this to work properly. The code follows. What am I doing wrong and why does it only show the image of the first listing in the database? Otherwise everything else works well. 

Thank you,
Suzi

Code: Select all

<? include ('db/connect.php'); 
foreach($_REQUEST as $key=>$value) {
        $$key=$value;
}

$sql = "SELECT * FROM manuf where manstat='yes' ORDER BY manname ASC";

$sql_result = mysql_query($sql,$connection)
	or die("Couldn't execute query.");
while ($row = mysql_fetch_array($sql_result)) {

	$manid= $row['manid'];
	$manname= $row['manname'];
	$manurl= $row['manurl'];
	$manimage= $row['manimage'];
	$manstat= $row['manstat'];
?>
<script language="javascript">
function show(id,x,y,tf) {
if (tf == true) {
id.style.display = "block"
id.style.left = x + "px"
id.style.top = y + "px"
}
if (tf == false) {
id.style.display = "none"
}
}
</script>
<div onmouseover="show(image1,200,200,true)" onmouseout="show(image1,200,200,false)">
<a href="http://<?=$manurl?>" target="_blank"><?=$manname?></a>
</div>

<img src="images/<?=$manimage?>" style="position:absolute;display:none" id="image1">
<? }; ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

I'm not sure exactly what the Javascript is doing, mostly because I didnt look, but may I suggest adding the HTML <img> tags etc within the PHP While statement as well.
suzithepid
Forum Newbie
Posts: 3
Joined: Wed Aug 01, 2007 10:56 am

Thanks for the quick response

Post by suzithepid »

I have tried that and the result is identical. Only the image of the first listing in the database appears.

Suzi
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

Your Image id is permanantely set at Image1, you need to put a counter in there or something..

Code: Select all

<?php
$counter = 0;
while ($row = mysql_fetch_array($sql_result)) {
$counter = $counter + 1;
$manid= $row['manid'];
$manname= $row['manname'];
$manurl= $row['manurl'];
$manimage= $row['manimage'];
$manstat= $row['manstat'];
?>
<script language="javascript">
function show(id,x,y,tf) {
if (tf == true) {
id.style.display = "block"
id.style.left = x + "px"
id.style.top = y + "px"
}
if (tf == false) {
id.style.display = "none"
}
}
</script>
<div onmouseover="show(Image<? echo $counter; ?>,200,200,true)" onmouseout="show(Image<? echo $counter; ?>,200,200,false)">
<a href="http://<?=$manurl?>" target="_blank"><?=$manname?></a>
</div>

<img src="images/<?=$manimage?>" style="position:absolute;display:none" id="Image<? echo $counter; ?>">
<? }; ?>
Also, I just noticed that all the images are Positioned in the Identical location, so they might be hiding under each other too.
suzithepid
Forum Newbie
Posts: 3
Joined: Wed Aug 01, 2007 10:56 am

THANK YOU!!!!

Post by suzithepid »

You're right. I knew I was too close to it! Thank you for your help!
Post Reply