Jump to content

php function called from onmouseover


timphp

Recommended Posts

Getting a bit desperate as I've tried a lot of things, so any help very appreicated!

 

The concept im struggling with works like this:

1.) There are graphics of people on a page. There is a textbox to the right of the screen which outputs data that corresponds to the tutor.

2.) What i want is that when a user rolls his mouse over the picture, the data in the textbox immediately updates, which is done via php

3.) The issue is thus calling a php function within onmouseover="" from a javascript command.

4.) The function only changes the values that should be displayed (but doesnt work anyway) - is there a way to test whether a php function is being called correctly? And do i need to include some kind of page refresher?

 

Thanks a lot for your help

 

******************************************

 

The code as I have it currently is this.

 

...

 

// Default setting to display a random persons data at page startup
<?


$username="removedforprivacy";
$password="removedforprivacy";
$database="tutors";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tutors";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=rand(0,5);


$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
$degree=mysql_result($result,$i,"degree");
$ib=mysql_result($result,$i,"ib");
$subjects=mysql_result($result,$i,"subjects");
$experience=mysql_result($result,$i,"experience");
$style=mysql_result($result,$i,"style");
$pic=mysql_result($result,$i,"pic");


?>



//This bit outputs all the graphics. Only the first immage calls the php updater function. $whichpic defines the flag for the person, which is passed to the updater function.
</p>
    <p class="bodytext"><a href="" onclick="" onmouseout="MM_swapImgRestore()" onmouseover="<? php updater($whichpic=1); ?>"><img src="../Tutors/Photos/tim2.gif" name="Image15" width="100" height="100" border="0" id="Image15" /></a><a href="max.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image16','','../Tutors/Photos/max1.gif',1)"><img src="../Tutors/Photos/max2.gif" alt="max" name="Image16" width="100" height="100" border="0" id="Image16" /></a><a href="nico.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image17','','../Tutors/Photos/nico1.gif',1)"><img src="../Tutors/Photos/nico2.gif" alt="nico" name="Image17" width="100" height="100" border="0" id="Image17" /></a><a href="sasha.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image18','','../Tutors/Photos/sasha1.gif',1)"><img src="../Tutors/Photos/sasha2.gif" alt="sasha" name="Image18" width="100" height="100" border="0" id="Image18" /></a>
</p>




//Where the php data is output
<p class="sideheader">FEATURED TUTOR</p>
<p><img src="<? echo " $pic"; ?>" width="200" height="200"></p>
    <p><strong>Name: </strong> <? echo "$name"; ?></p>
    <p><strong>Degree: </strong> <? echo "$degree"; ?></p>
    <p><strong>IB: </strong> <? echo "$ib"; ?></p>
    <p><strong>Subjects Taught: </strong> <? echo "$subjects"; ?></p>
    <p><strong>Teaching Experience: </strong> <br /> <? echo "$experience"; ?>
     </p>
    <p><strong>Teaching Style:<br /> </strong><? echo "$style"; ?>
.</strong>    </p>
<p><!-- end .sidebar2 --></p>
</div>





// The updater function to call, which changes the information displayed
<?
php

function updater($whichpic)
{

$i = $whichpic;

$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
$degree=mysql_result($result,$i,"degree");
$ib=mysql_result($result,$i,"ib");
$subjects=mysql_result($result,$i,"subjects");
$experience=mysql_result($result,$i,"experience");
$style=mysql_result($result,$i,"style");
$pic=mysql_result($result,$i,"pic");
}
?>

 

 

Link to comment
Share on other sites

2.) What i want is that when a user rolls his mouse over the picture, the data in the textbox immediately updates, which is done via php

You can't call PHP function from onmouseover. You may call only JS function. If you any information from the server, use AJAX.

Link to comment
Share on other sites

Thanks sergei. That's fine, I can call a javascript function, which can in turn call a php function (something like below). My question is then, how do i make the php loader() function work? Ie make the page update the values taken from the sql server based on an input?

 

//This bit outputs all the graphics. Only the first immage calls the php updater function. $whichpic defines the flag for the person, which is passed to the updater function.
</p>
    <p class="bodytext"><a href="" onclick="" onmouseout="MM_swapImgRestore()" onmouseover="updater(2); ?>"><img src="../Tutors/Photos/tim2.gif" name="Image15" width="100" height="100" border="0" id="Image15" /></a><a href="max.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image16','','../Tutors/Photos/max1.gif',1)"><img src="../Tutors/Photos/max2.gif" alt="max" name="Image16" width="100" height="100" border="0" id="Image16" /></a><a href="nico.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image17','','../Tutors/Photos/nico1.gif',1)"><img src="../Tutors/Photos/nico2.gif" alt="nico" name="Image17" width="100" height="100" border="0" id="Image17" /></a><a href="sasha.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image18','','../Tutors/Photos/sasha1.gif',1)"><img src="../Tutors/Photos/sasha2.gif" alt="sasha" name="Image18" width="100" height="100" border="0" id="Image18" /></a>
</p>


// The updater function to call, which changes the information displayed
<script language = "Javascript">

function loader()
{

//a call to make the php updater function run, which just updates the text to be output
}
</script>

//whats missing now is eaxctly what the php updater() function should say?

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.