Jump to content


Issue displaying data from a database


1 reply to this topic

#1 tones

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 19 February 2008 - 08:50 PM

Ok i've been working on an application form cms. Its going to store application forms submitted by candidates for say a staff position. The section i'm having troubles with is displaying references specific to a candidate. first page will list the candidates, and you click a candidate name and it displays a page showing the references specific to that person from another database table, using the switch function.

here is the table layout

[quote]CREATE TABLE `references` (

`id` int(11) NOT NULL auto_increment,

`aid` int(11) NOT NULL,

`author` varchar(25) NOT NULL default '',

`content` text NOT NULL,

`postdate` tinytext NOT NULL,

PRIMARY KEY (`id`)

)[/quote]
and here's the code for the references.

[quote]///////////////////////////////////////////////////////////////////////////////////////
// User References
///////////////////////////////////////////////////////////////////////////////////////
case 'Ref':
$a = mysql_query("SELECT * FROM applicants WHERE status = 'pending' ORDER BY postdate DESC LIMIT 100");
echo '
<table width="100%" border="0" cellpadding="10" cellspacing="0">
<tr>
<th><center>Member ID</center></th>
<th><center>Username</center></th>
<th><center>Account Type</center></th>
<th><center>Timezone</center></th>
<th><center>Sign Up</center></th>
<th><center>Status</center></th>
<th><center>Rating</center></th>
<th><center>Apply Date</center></th>
</tr>';
if (mysql_num_rows($a) == 0) {
echo ' <tr>
<td colspan="7">There are no applications to display!</td>
</tr>';
} else {
while ($b = mysql_fetch_object($a)) {
echo ' <tr>
<td><center><b><a href="manage.php?act=ShowRef&tid='.$b->member.'" target="_self">'.$b->member.'</a></b></center></td>
<td><center>'.$b->name.'</center></td>
<td><center>'.$b->account.'</center></td>
<td><center>'.$b->timezone.'</center></td>
<td><center>'.$b->joindate.'</center></td>
<td><center>'.$b->status.'</center></td>
<td><center>'.$b->rating.'</center></td>
<td><center>'.$b->postdate.'</center></td>
</tr>';
}
}
echo '</table>';
break;
///////////////////////////////////////////////////////////////////////////////////////
// References
///////////////////////////////////////////////////////////////////////////////////////
case 'ShowRef':
$id = $_GET['tid'];
if(isset($_POST['reference'])) {

$name = addslashes(trim($_POST['name']));
$ref = addslashes(trim($_POST['ref']));
$date = date("Y-m-j");

if((( empty($name) ) || ( empty($ref) ))) {
echo '<script>alert("One or more fields was left empty, please try again.");</script>';
echo '<script>history.back(1);</script>';
exit;
}
$insert = mysql_query("INSERT INTO `references` (`aid`, `author`, `content`, `postdate`) VALUES ('$id','$name','$ref','$date')")or die(mysql_error());
if($insert) {
echo '<div id="success">
<p>Thanks for the reference!</p>
</div>';
} else {
echo '<div id="error">
<p>We are sorry, there appears to be a problem with our script at the moment.</p>
<p>Please try again later.</p>
</div>';
}
} else {
echo '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
<form method="post">
<tr>
<td><center><b>Name:</b><br><input name="name" type="text" id="name"><br><br>
<b>Comment:</b><br><textarea name="ref" rows="5" cols="45" id="ref"></textarea><br><br>
<input name="reference" type="submit" value="Submit"></center></td>
</tr>
</form>
</table>';
}
$comments = mysql_query("SELECT * FROM `references` WHERE `aid` = '$id' ORDER BY `postdate` DESC");
if (mysql_num_rows($comments) == 0) {
echo '<div id="error">There are no references for this user!</div>';
} else {
echo '<table width="70%" border="0" cellpadding="0" cellspacing="0" align="center">';
while ($r = mysql_fetch_object($comments)); {
echo '<tr class="secondRow"><td><b><u>'.$r->author.' - '.$r->postdate.'</u></b><br> '.$r->content.'</td></tr>';
}
echo '</table>';
}
break;[/quote]

Ok it writes the references to the database, and it stores the member it is specific to, but i cant get it to display the refereces as per the $id it calls for.

Any help would be awesome thanks.

Edited by tones, 19 February 2008 - 08:52 PM.


#2 tones

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 28 February 2008 - 06:07 PM

This thread can be closed now, I've plugged away at it and finally got it working.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users