Hello,
One more problem(I promise this is the last one!)
I want it to display ‘Comment edited by Admin etc’ if there is a ‘Y’ in the admin field of the table. Unfortunately, the following displays it even if there is an ‘N’ in the field :
[code=php]if ($row4[2] = ‘Y’) {
echo ‘<small> – Comment edited by Admin on ‘ . $row4[‘udate’] . ‘</small></p>’;
}
else {
echo ‘<br /></p>’;
}
}
Obviously if there is an ‘N’ in there, I don’t want to display anything ?
For comments that have an [B]‘N’
[CODE]– Comment edited by Admin on 0000-00-00
For comments that have an [B]‘Y’
[CODE]– Comment edited by Admin on 2006-04-01
Any clues ?
The problem code is down at the bottom of this script.
[code=php]
<?
require_once (‘./includes/config.inc.php’);
$page_title = ‘Picture’;
include (‘./includes/header.html’);
function par($str) {
return eregi_replace(“rnrn”, “</p>n<p>”, $str);
}
// Page Header
echo ‘<h2>Picture</h2>’;
require_once (‘../mysql_connect.php’); // Connect to the database
if (isset($_POST[‘submitted’])) { // Handle the Comments form.
// Check for Comments, use strip_tags
$com = strip_tags(stripslashes($_POST[‘comment’]));
if (empty($com)) {
echo ‘<h3>Please fill in the comments field</h3>’;
include (‘./includes/footer.html’);
exit;
}
if ($com) {
if(!$_SESSION || !$_SESSION[‘first_name’]) {
echo ‘<h3>For this area you will need to login.</h3>’;
echo ‘<b>Options :</b>’;
echo ‘<ul><li><a href=”javascript:history.go(-1)”>Go back to the picture</a></li>’;
echo ‘<li><a href=”login.php”>Login</a></li>’;
echo ‘<li><a href=”register.php”>Register</a></li>’;
echo ‘<li><a href=”forgot_password.php”>Forgot Password</a></li>’;
include (‘./includes/footer.html’);
exit;
}
$query = “SELECT user_id FROM users WHERE first_name = ‘$_SESSION[first_name]'”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
$row = mysql_fetch_array($result);
$query5 = “SELECT id FROM user_images WHERE id = ‘imgid'”;
$result5 = mysql_query($query5) or trigger_error(“Query: $query5n<br />MySQL Error: ” . mysql_error());
$row5 = mysql_fetch_array($result5);
$query6 = “SELECT id, comment, uid, imgid FROM comments WHERE uid = ” . $_SESSION[‘user_id’] . ” AND imgid = ” . $_POST[‘id’] . “”;
$result6 = mysql_query($query6) or trigger_error(“Query: $query6n<br />MySQL Error: ” . mysql_error());
$row6 = mysql_fetch_array($result6);
$commented = $row6[‘comment’];
} else { // If it didn’t work correctly.
echo ‘<p><font color=”red” size=”+1″>Please type your comment into the Comments field, and try again.</font></p>’;
}
if (mysql_num_rows($result6) < 1) {
$query2 = “INSERT INTO comments(comment,uid,imgid) VALUES(‘$com’, $row[user_id], $_POST[id])”;
$result2 = mysql_query($query2) or trigger_error(“Query: $query2n<br />MySQL Error: ” . mysql_error());
// Finish the page
echo ‘<H3>Thank you for adding a comment for the picture.</h3>’;
include (‘./includes/footer.html’); // Include the HTML footer.
exit();
}
else {
echo ‘<font color=”red”>You have already commented </font>’ . $commented . ‘<font color=”red”> for the picture!</font>’;
}
}
$query = “SELECT img_src, content_type, image_name, area, cameratype, dateUpload, comments, approved, lon, lat, width, height, aid, user_id FROM user_images WHERE id = $_GET[id] AND approved=’Y'”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
$row = mysql_fetch_array($result);
if (mysql_num_rows($result) == 1) {
$query3 = “SELECT user_id, username FROM users WHERE user_id = $row[user_id]”;
$result3 = mysql_query($query3) or trigger_error(“Query: $query3n<br />MySQL Error: ” . mysql_error());
$row3 = mysql_fetch_array($result3);
echo ‘<p><b>Title : </b>’ . $row[‘image_name’] . ‘<b> , Area : </b>’ . $row[‘area’] . ‘</p>’;
echo ‘<p><b>Posted by : </b><a href=”view_profile.php?id=’ . $row3[‘user_id’] . ‘”>’ . $row3[‘username’] . ‘</a> on ‘ . $row[‘dateUpload’] . ‘</p>’;
echo ‘<p><b>Latitude : </b>’ . round($row[‘lat’], 2) . ‘N <b>Longitude : </b>’ . round($row[‘lon’], 2) . ‘W </p>’;
echo ‘<p><b>Comments : </b><br>’ . par($row[‘comments’]) . ‘</p>’;
if ($row[‘width’] < 1 && $row[‘height’] < 1) {
echo ‘<img src=”show_picture.php?id=’. $_GET[‘id’] .'” alt=”‘ . $row[‘image_name’] . ‘”><p></p>’;
} else {
echo ‘<a href=”show_picture.php?id=’. $_GET[‘id’] .'” target=”_blank”><img src=”show_picture.php?id=’. $_GET[‘id’] .'” alt=”‘ . $row[‘image_name’] . ‘” width=”‘ . $row[‘width’] . ‘” height=”‘ . $row[‘height’] . ‘” border=”1″></a><p></p>’;
}
echo ‘<i><a href=”problempic.php?id=’ . $_GET[‘id’] . ‘”>Notify Admin about “‘ . $row[‘image_name’] . ‘” Picture ?</a></i><br><br>’;
echo ‘<b>Rate a picture today!</b>’;
echo ‘<form name=”rate” action=”vote.php” method=”POST”>’;
echo ‘0<input type=”radio” name=”rating” value=”0″ onClick=”this.form.submit();”> 1<input type=”radio” name=”rating” value=”1″ onClick=”this.form.submit();”> 2<input type=”radio” name=”rating” value=”2″ onClick=”this.form.submit();”> 3<input type=”radio” name=”rating” value=”3″ onClick=”this.form.submit();”> 4<input type=”radio” name=”rating” value=”4″ onClick=”this.form.submit();”> 5<input type=”radio” name=”rating” value=”5″ onClick=”this.form.submit();”>’;
echo ‘<input type=”hidden” name=”submitted” value=”TRUE” />’;
echo ‘<input type=”hidden” name=”image_name” value=”‘.$row[‘image_name’].'” />’;
?>
<input type=”hidden” name=”id” value=”<?=$_GET[‘id’];?>”>
<?
$query = “SELECT AVG(vote) AS avgvote FROM vote WHERE imgid = $_GET[id]”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
$row = mysql_fetch_array($result);
echo ‘</form>Current Average Vote: ‘. round($row[‘avgvote’], 2) .'<hr>’;
echo ‘<p><u><b>Comments from other users :</b></u><br />’;
$row = mysql_fetch_array($result);
$query4 = “SELECT c.comment, c.udate, c.admin, u.user_id, u.username FROM comments as c, users as u WHERE imgid = $_GET[id] AND uid = user_id”;
$result4 = mysql_query($query4) or trigger_error(“Query: $query4n<br />MySQL Error: ” . mysql_error());
while ($row4 = mysql_fetch_array($result4)) {
echo ‘<p>’ . $row4[‘comment’] . ‘ – <a href=”view_profile.php?id=’ . $row4[‘user_id’] . ‘”>’ . $row4[‘username’] . ‘</a><br />’;
if ($row4[2] = ‘Y’) {
echo ‘<small> – Comment edited by Admin on ‘ . $row4[‘udate’] . ‘</small></p>’;
}
else {
echo ‘<br /></p>’;
}
}
echo ‘<p><u>Add your own comment on this image</u></p>’;
echo ‘<form action=”picture.php?id=’.$_GET[‘id’].'” method=”POST”><textarea NAME=”comment” COLS=40 ROWS=6></TEXTAREA><br /><br />’;
echo ‘<INPUT TYPE=SUBMIT VALUE=”Add your Comment” name=”submit”><br /><br />’;
echo ‘<input type=”hidden” name=”submitted” value=”TRUE” />’;
?>
<input type=”hidden” name=”id” value=”<?=$_GET[‘id’];?>”>
<?
echo ‘</form>’;
}
else {
echo ‘Image has yet to be approved’;
}
include (‘./includes/footer.html’);
?>
Many thanks once more for taking a look.