showing all results in a table

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
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

showing all results in a table

Post by ekosoftco »

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

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&#058;getPage('<?php echo "" . $title . ""; ?>')"><?php echo "<td>" . $title . "</td></tr></table>"; ?></a></font>
<?
}
?>
<div id="content">
<p>*</p>
</div>
</body>
</html>
and the page if you want to see
http://cyril.ulmb.com/emp/employment.php
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: showing all results in a table

Post by andym01480 »

No idea about the ajax bit, but have a look at line 14 - only $dept -

Code: Select all

<td>$title</td></tr>
And where are you closing the Where loop?
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Re: showing all results in a table

Post by ekosoftco »

i close the loop right after calling the $title array, i only put $dept and $title once b/c its an array and shows them all up, just only one goes in the table :(
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Re: showing all results in a table

Post by ekosoftco »

i got it. im retarded i put the </table> inside of the loop, just needed to move it out of the loop.
you helped me see that xD
thanks!
Post Reply