Page 1 of 1

need correct position

Posted: Thu Jan 31, 2008 10:28 am
by ekosoftco
I've been working on this a while :( i have a code where if you click on a title it will show up the desc and stuff, and i got it to work with a few different codes, but the problem i have now is not it showing up the right stuff, but showing it up in the right place. i have 3 different titles, and i need descriptions to show up under each one according to the title. its all in mysql, and im using php js bla bla bla :)
heres my code

Code: Select all

<?php
ob_start();
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Our wonderful AJAX page!</title>
<script language="javascript" type="text/javascript">
function getPage(page){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'text.php?page='; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file + page, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ //Make sure there is something in the content variable
                      document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
</script>
</head>
 
<body>
<?php
include('../pageedit/conf.php');
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect');
mysql_select_db($db) or die ('Unable to select database!');
$query = "SELECT department, title, description, job FROM employment";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
while($row = mysql_fetch_object($result))
 {
 $title = $row->title;
 $dept = $row->department;
?>
<font color="#000000"><a href="javascript&#058;getPage('<?php echo "" . $title . ""; ?>')"><?php echo "" . $title . ""; ?></a></font>
<div id="content">
<p>*</p>
</div>
<?
}
?>
</body>
</html>
and heres an example of what it does so you can see better what im saying.
http://cyril.ulmb.com/emp/employment.php
click on the titles, and im sorry about the bad words. :/
i have the content pulled up showing up in a div, and the div is technically reproduced with every field in the db (you can tell b/c the * under each title is default for the div), but the content only shows up in the first produced div no matter what.

Re: need correct position

Posted: Fri Feb 01, 2008 9:56 am
by ekosoftco
anyone have any ideas? ive tried putting it all in the loop in php, including the js, but that changed nothing

Re: need correct position

Posted: Fri Feb 01, 2008 10:34 am
by aceconcepts
What you wanna do is write a loop within a loop

See viewtopic.php?f=1&t=77963

Its at the bottom.

Re: need correct position

Posted: Fri Feb 01, 2008 12:25 pm
by ekosoftco
ok, i tried that, this is the code im using to do it.

Code: Select all

<?php
ob_start();
session_start();
include('../pageedit/conf.php');
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect');
mysql_select_db($db) or die ('Unable to select database!');
$query = "SELECT department, title, description, job FROM employment ORDER BY department";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
while($row = mysql_fetch_object($result))
 {
 $title = $row->title;
 $dept = $row->department;
 echo "" . $dept . "<br>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Our wonderful AJAX page!</title>
<script language="javascript" type="text/javascript">
function getPage(page){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'text.php?page='; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file + page, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to recieve data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ //Make sure there is something in the content variable
                      document.getElementById('content').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
return;
}
</script>
</head>
 
<body>
<?php
$bquery = "SELECT department, title, description, job, end, start FROM employment WHERE title = '$title'";
$bresult = mysql_query($bquery) or die ("Error in query: $bquery. " . mysql_error());
while($brow = mysql_fetch_object($bresult))
 {
?>
<font color="#000000"><a href="javascript&#058;getPage('<?php echo "" . $title . ""; ?>')"><?php echo "" . $title . ""; ?></a></font>
<div id="content">
<p>*</p>
</div>
<?
}
echo "<br>";
}
?>
</body>
</html>
but its still doing the exact same thing, is there a different way i should be doing this?

it might be better to view the page im working on so you see whats happening exactly
http://cyril.ulmb.com/emp/employment.php

Re: need correct position

Posted: Fri Feb 01, 2008 10:13 pm
by ekosoftco
ive tried a few more things, like moving around the while($row) stuff but to no prevail. anyone plz any other ideas?

Re: need correct position

Posted: Sat Feb 02, 2008 9:23 am
by ekosoftco
instead of doing a loop in a loop would indexing inside the loop change anything?