Page 1 of 1

Showing all results

Posted: Wed Jan 23, 2008 3:05 pm
by ekosoftco
I have a code where it takes all results from an employment table and puts them into html tables. Im using java to make it where you click on the title and the rest of it shows up. my problem is when it supposed to echo all the results, it picks the newest one only, instead of sorting and showing all of them. once again im lost, most of the code is in php, but i am inculding the java as well, ill post it in the php part for now (sorry if im not supposed to i dont know) :(

Code: Select all

<?php
ob_start();
session_start();
//includes
require('configstaff.php');
include('pageedit/conf.php');
include('pageedit/functions.php');
//open databse connection
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect');
 
//select database
mysql_select_db($db) or die ('Unable to select database!');
 
// generate and execute query
$query = "SELECT department, title, description, job FROM employment ORDER BY end";
 
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
 
// get resulset as object
$row = mysql_fetch_object($result);
 
//print details
if ($row)
{
$dept = $row->department;
$title = $row->title;
$desc = $row->description;
$job = $row->job;
}
?>
<!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>
<style type="text/css">
<!--
 
div{width:100px; font-family:arial; font-size:14px; color:#000000;}
span{width:100px; visibility:visible;}
//-->
</style>
 
<script type="text/javascript">
<!-- 
function clearcell()
{
document.getElementById("information").innerHTML ='<div> *</div>';
}
function description()
{
document.getElementById("information").innerHTML ='<div><?php echo "Description: " . $desc . "<br>"; ?>
<?php echo "Job: " . $job . ""; ?></div>';
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body onload="clearcell();">
<?php if ($title != '')
{
?>
<table><tr><td>
<?php echo "Department: " . $dept . "<br>"; ?>
</td></tr><tr><td>
Title: <a href=javascript&#058;description()><span onclick=this.style.visibility='visible'><?php echo "" . $title . ""; ?></span></a><br>
</td></tr><tr><td>
<div id="information"></div>
</td></tr></table>
<?php
}else{ 
echo "There are no availablilities right now!";
}
?>

Re: Showing all results

Posted: Wed Jan 23, 2008 4:27 pm
by John Cartwright
You need to iterate the result set. Right now your only fetching a single row, i.e.

Code: Select all

// get resulset as object
$row = mysql_fetch_object($result);
when you should be looping

Code: Select all

while ($row = mysql_fetch_object($result)) {
 // the rest of your stuff in here
}

Re: Showing all results

Posted: Wed Jan 23, 2008 6:39 pm
by ekosoftco
awsome it worked, thank you! i do have one more question though on another part of the code. where you see it pull up the div in the html, i cant figure out how to pull it up for each title. it only works on the first one, no matter which link you click for the title, and it only shows up under the first field in the db. its probably something simple i overlooked like looping :(

Re: Showing all results

Posted: Wed Jan 23, 2008 9:32 pm
by Kieran Huggins
you may need to post some code... not sure exactly what you mean there

Re: Showing all results

Posted: Thu Jan 24, 2008 12:29 am
by ekosoftco
ok, i have this code

Code: Select all

<script type="text/javascript">
<!-- 
function clearcell()
{
document.getElementById("information").innerHTML ='<div> *</div>';
}
function description()
{
document.getElementById("information").innerHTML ='<div><?php echo "Description: " . $desc . "<br>"; ?>
<?php echo "Job: " . $job . ""; ?></div>';
}
//-->
</script>
and this one

Code: Select all

Title: <a href=javascript&#058;description()><span onclick=this.style.visibility='visible'><?php echo "" . $title . ""; ?></span></a><br>
</td></tr><tr><td>
<div id="information"></div>
theyre all in the original code i posted above. what im trying to do is make it where the $title is clickable and when you click it from one of the results it will show up the $desc and $job according to that $title, all in the row in the db. i hope im making sense :(
my problem is it only shows up the first results $job and $desc when you clikc on any $title. i have all the $titles showing up now, i just need to have them show the correct info in the correct spot when you click on different $titles.
heres an example too
http://cyril.ulmb.com/employment.php

Re: Showing all results

Posted: Thu Jan 24, 2008 3:04 am
by Rovas
Want you want is complicated to implement because you need to know which title has been clicked.
You could use XMLHttpRequest (in other terms AJAX) to send the data (title) and receive the information you want (description, job). It' s not complicated, look at this example.
But if you want to do it your way you need to have an identifier for each title and to use JavaScript to read that identifier and display it. You make in JS a function that makes a window which takes a parameter a number or a letter (give it in php) and for that number letter you associate the data you want to display.

Re: Showing all results

Posted: Thu Jan 24, 2008 10:38 am
by ekosoftco
gotcha ;)
i think ill take the ajax road. appreciate it.