showing all results in a table
Posted: Mon Feb 04, 2008 11:33 am
what im trying to do is put all the results in a table. its only putting the first result in the table, and then putting the other two under it out of the table. here is the code
and the page if you want to see
http://cyril.ulmb.com/emp/employment.php
Code: Select all
<?php
ob_start();
session_start();
include('../pageedit/conf.php');
echo "<table border=1><tr><td>Department</td><td>Title</td></tr>";
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect');
mysql_select_db($db) or die ('Unable to select database!');
$query = "SELECT * 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 "<tr><td>" . $dept . "</td>";
?>
<!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>
<font color="#000000"><a href="javascript:getPage('<?php echo "" . $title . ""; ?>')"><?php echo "<td>" . $title . "</td></tr></table>"; ?></a></font>
<?
}
?>
<div id="content">
<p>*</p>
</div>
</body>
</html>http://cyril.ulmb.com/emp/employment.php