Titan85
03-01-2007, 03:19 AM
Hello, I am trying to make a script that will allow a user to comment once on a job done for them. I got it working fine to only allow them to leave one comment, but then I realized that on user may have multiple jobs to comment and that I need them to be able to comment once on each job. I have a page that shows is supposed to show the jobs available for commenting, but when I run the page, I get nothing. Here is the code:
<?php
// Get username
$user = $_SESSION['user'];
// Query to get job data
$sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
$result = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
$row = mysql_fetch_array($result);
// Get number of results
$results = mysql_num_rows($result);
// If there are no results
if($results < 1) {
echo '
There are no jobs availible for you to comment. Contact me <a href="http://echo-designes.com/contact.php">here</a> to have a job done.
<br />
';
}
// Find out whether to display "are" or "is" and "jobs" or "job"
if($results = 1) {
$are = "is";
$job = "job";
}
else {
$are = "are";
$job = "jobs";
}
// If there are results and form is not active
if($results >= 1 && !$_GET['page']) {
// Tell how many jobs can be commented
echo '
There '.$are.' <i>'.$results.'</i> '.$job.' that you may comment.
<br /><br />
';
echo 'Chose the job you would like to comment.
<br /><br />';
// get job data
$sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
$jobs = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
$j = mysql_fetch_array($jobs);
$title = $j['title'];
$comments = mysql_query("SELECT * FROM `comments` WHERE job = '$title'") or die ('Error Checking Comments! <br />' .mysql_error());
$c = mysql_fetch_array($comments);
// Display jobs
while($job = mysql_fetch_array($jobs)) {
if($job['title'] !== $c['title']) {
echo '
<a href="comment.php?page=add&id='.$job['id'].'">'.$job['title'].'</a>
<br />';
}
}
}
// If add was hit
if($_GET['page'] == "add") {
require('add.php');
}
?>The pages reads that there is indeed a job to comment, but does not display the link to comment it (in the while statement). Thanks
<?php
// Get username
$user = $_SESSION['user'];
// Query to get job data
$sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
$result = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
$row = mysql_fetch_array($result);
// Get number of results
$results = mysql_num_rows($result);
// If there are no results
if($results < 1) {
echo '
There are no jobs availible for you to comment. Contact me <a href="http://echo-designes.com/contact.php">here</a> to have a job done.
<br />
';
}
// Find out whether to display "are" or "is" and "jobs" or "job"
if($results = 1) {
$are = "is";
$job = "job";
}
else {
$are = "are";
$job = "jobs";
}
// If there are results and form is not active
if($results >= 1 && !$_GET['page']) {
// Tell how many jobs can be commented
echo '
There '.$are.' <i>'.$results.'</i> '.$job.' that you may comment.
<br /><br />
';
echo 'Chose the job you would like to comment.
<br /><br />';
// get job data
$sql = "SELECT * FROM `jobs` WHERE username = '$user' ORDER BY id DESC";
$jobs = mysql_query($sql) or die ('Error Getting Job Data! <br />' .mysql_error());
$j = mysql_fetch_array($jobs);
$title = $j['title'];
$comments = mysql_query("SELECT * FROM `comments` WHERE job = '$title'") or die ('Error Checking Comments! <br />' .mysql_error());
$c = mysql_fetch_array($comments);
// Display jobs
while($job = mysql_fetch_array($jobs)) {
if($job['title'] !== $c['title']) {
echo '
<a href="comment.php?page=add&id='.$job['id'].'">'.$job['title'].'</a>
<br />';
}
}
}
// If add was hit
if($_GET['page'] == "add") {
require('add.php');
}
?>The pages reads that there is indeed a job to comment, but does not display the link to comment it (in the while statement). Thanks