I'm am using a javascript menu and want to incorporate php/mysql to determine the menu height. The code in the header section for the dimensions are:
<script language="javascript">
new ypSlideOutMenu("menu3", "right", 80, 140, 150, 180)
</script>
The second set of numbers are the numbers of concern (i.e. 150, 180). In particular is the 180. This is the height of the menu that contains the names of people in the mysql database. So, if a person is added/removed from the database, I need the height to adjust accordingly.
The body of the html document contains the following code which accesses the mysql database for a list of faculty members:
<div id="menu3Container">
<div id="menu3Content" class="menu" align="center">
<table border="0">
<?php
$fac_array = @mysql_query('SELECT faculty.ID, FLNAME FROM faculty ORDER BY LNAME');
if (!$fac_array) {
die('<h2>Error retrieving faculty from database!</h2><br>' .
'Error: ' . mysql_error());
}
while ($faculty = mysql_fetch_array($fac_array)) {
$fid = $faculty['ID'];
$flname = $faculty['FLNAME'];
echo ('<tr valign=center>
<td><a href="http://webserver.nsm.tridenttech.edu?pg ... .'</a></tr>');
}
?>
</table>
</div>
Now, I have the php code which will count the number of rows in the database which I can then multiply that number times the number of pixels per entry, but I thought that php could only be used in the body of an html document and this would require me to use the variable with the row count in the js in the header. I'm confused. Can someone shed some light on the matter for me? Or, if you know of a good js menu or dhtml menu script that easily works with php please let me know. I need a vertical menu possibly with multiple submenus.
Many thanks,
Chris
PHP and Javascript
Moderator: General Moderators
php can be located in any part of an html document. so:
is the same as:
Variables are kept throughout the entire script also. eg:
As far as a js/dhtml menu is concerned, you might want to look at dynamicdrive.com they have a couple good menu scripts there.
Code: Select all
<?php echo 'I''m located before the start of an html document.'; ?>
<html><head><title>Foo</title></head>
<body>
body of document
</body>
</html>Code: Select all
<html><head><title>Foo</title></head>
<body>
body of document
</body>
</html>
<?php echo 'I''m located waaay at the bottom.'; ?>Code: Select all
<?php
$variableName = 'I am a variable';
?>
<html><head><title>foo</title></head>
<body>
<?php echo $variableName ?>
The above echo's the content of the variable $variableName which is: "I am a variable"
</body>
</html>As far as a js/dhtml menu is concerned, you might want to look at dynamicdrive.com they have a couple good menu scripts there.
Thats a big help. Thanks. I'm almost there now. However, I don't know how to incorporate php with javascript. Here's the code I have so far:
This part of the code determines how many records in the faculty table and multiplies that number to 20 which is the number of pixels to show only one member.
<head>
<?php
$facultycount_array = @mysql_query('SELECT count(ID) FROM faculty');
if (!$facultycount_array) {
die('<h2>Error retrieving faculty from database!</h2><br>' .
'Error: ' . mysql_error());
}
$faculty = mysql_fetch_array($facultycount_array);
$height=$faculty[0]*20;
?>
This is javascript is related to the menu and dictates the position of the menu (first two numbers) and the dimension of the menu (second two numbers).
<script language="javascript" src="/ypSlideOutMenusC.js"></script>
<script language="javascript">
new ypSlideOutMenu("menu3", "right", 80, 140, 150, 180)
</script>
</head>
What I want to do is change the 180 number to the variable $height so that as the number of faculty change, the size of the menu changes accordingly. The problem I'm running into is that no matter how I place the variable in the javascript, $height, or <?php $height?>, or even placing the entire js within the php tags, the menu doesn't work. What happens is that all the faculty members are displayed at the bottom of the webpage.
Here is the code I put in the body of the html document:
This is the last table of the webpage before the menu related items.
<table>
<tr>
<td height="30" valign="middle" bgcolor="#DDE1DE" align="center">
<div style="text-align: center; padding-top: 2px; font-size: 10px">Chris Obenberger - Webmaster</div></td>
</tr>
</table>
This part relates to the menu:
<div id="menu3Container">
<div id="menu3Content" class="menu" align="center">
<table border="0">
<?php
$fac_array = @mysql_query('SELECT faculty.ID, FLNAME FROM faculty ORDER BY LNAME');
if (!$fac_array) {
die('<h2>Error retrieving faculty from database!</h2><br>' .
'Error: ' . mysql_error());
}
while ($faculty = mysql_fetch_array($fac_array)) {
$fid = $faculty['ID'];
$flname = $faculty['FLNAME'];
echo ('<tr valign=center>
<td><a href="http://webserver.nsm.tridenttech.edu?pg ... .'</a></tr>');
}
?>
</table>
</div>
Now, if I leave the 180 in the upper script, the menu works fine. As soon as I try to put in a variable, the faculty are displayed at the bottom of the webpage, underneith the last table. Obviously, I'm not using the correct format for the js.
How can I incorporate the two scripting languages?
Thanks.
This part of the code determines how many records in the faculty table and multiplies that number to 20 which is the number of pixels to show only one member.
<head>
<?php
$facultycount_array = @mysql_query('SELECT count(ID) FROM faculty');
if (!$facultycount_array) {
die('<h2>Error retrieving faculty from database!</h2><br>' .
'Error: ' . mysql_error());
}
$faculty = mysql_fetch_array($facultycount_array);
$height=$faculty[0]*20;
?>
This is javascript is related to the menu and dictates the position of the menu (first two numbers) and the dimension of the menu (second two numbers).
<script language="javascript" src="/ypSlideOutMenusC.js"></script>
<script language="javascript">
new ypSlideOutMenu("menu3", "right", 80, 140, 150, 180)
</script>
</head>
What I want to do is change the 180 number to the variable $height so that as the number of faculty change, the size of the menu changes accordingly. The problem I'm running into is that no matter how I place the variable in the javascript, $height, or <?php $height?>, or even placing the entire js within the php tags, the menu doesn't work. What happens is that all the faculty members are displayed at the bottom of the webpage.
Here is the code I put in the body of the html document:
This is the last table of the webpage before the menu related items.
<table>
<tr>
<td height="30" valign="middle" bgcolor="#DDE1DE" align="center">
<div style="text-align: center; padding-top: 2px; font-size: 10px">Chris Obenberger - Webmaster</div></td>
</tr>
</table>
This part relates to the menu:
<div id="menu3Container">
<div id="menu3Content" class="menu" align="center">
<table border="0">
<?php
$fac_array = @mysql_query('SELECT faculty.ID, FLNAME FROM faculty ORDER BY LNAME');
if (!$fac_array) {
die('<h2>Error retrieving faculty from database!</h2><br>' .
'Error: ' . mysql_error());
}
while ($faculty = mysql_fetch_array($fac_array)) {
$fid = $faculty['ID'];
$flname = $faculty['FLNAME'];
echo ('<tr valign=center>
<td><a href="http://webserver.nsm.tridenttech.edu?pg ... .'</a></tr>');
}
?>
</table>
</div>
Now, if I leave the 180 in the upper script, the menu works fine. As soon as I try to put in a variable, the faculty are displayed at the bottom of the webpage, underneith the last table. Obviously, I'm not using the correct format for the js.
How can I incorporate the two scripting languages?
Thanks.