hey everyone,
I’m making a new part for my site, so people can add comments to picture other people have uploaded. The way i’ve done this is by making a tread that comes off each image. what i’m having a problem with is if there are no comments, I want it to say “No comments added” and not to display the table that the comment would of been displayed in.
here’s my script.
[code=php]<table border=”0″ cellspacing=”0″ cellpadding=”2″ width=”504″>
<!–DWLayoutTable–>
<tr>
<td height=”20″ colspan=”2″ bgcolor=”#330099″ id=”comtop” class=”coms”><?php $id = $_SESSION[‘id’];
mysql_connect(“host”,”user”,”password”)
or die(“Could not connect”);
mysql_select_db(“unicyclep1”)
or die(“Could not select database”);
$sql2 = “SELECT COUNT(*) as `count` FROM image_com WHERE image_id = ‘$id’ ORDER BY `date`”;
$result = mysql_query($sql2) or die(“<br><br><span class=”subHeader”>No Images Uploaded</span>”);
$row = mysql_fetch_array($result);
$numrows = $row[‘count’];
$p = (isset($_GET[“comment”]) and is_numeric($_GET[“comment”]) and ($_GET[“comment”] > 0) and ($_GET[“comment”] <= $numrows))
? $_GET[“comment”]
: $numrows ;
$sql1 = “SELECT * FROM image_com WHERE image_id = ‘$id’ ORDER BY id LIMIT 1 OFFSET “.($p = 0);
$result = mysql_query($sql1) or die(“<br><br><span class=”subHeader”>No Images Uploaded</span>”);
$r = mysql_fetch_assoc($result); ?><?php echo $r[‘date’];
?> </td>
</tr>
<tr>
<td width=”128″ height=”89″ align=”center” valign=”top” id=”style5″>
<p class=”com”><?php echo $r[‘user_name’];
?></p><form action=”viewprofile.php” method=”post”>
<input type=”hidden” name=”username” value=”<?php echo $r[‘user_name’] ?>”>
<input type=”submit” value=”View Profile”></form></td>
<td width=”368″ valign=”top” id=”style10″><p class=”com”><?php echo $r[‘comment’]; ?></p></td>
</tr>
</table>
<br>
<table border=”0″ cellspacing=”0″ cellpadding=”2″ width=”504″>
<!–DWLayoutTable–>
<tr>
<td height=”20″ colspan=”2″ bgcolor=”#330099″ class=”coms” id=”comtop”><?php $id = $_SESSION[‘id’];
mysql_connect(“host”,”user”,”password”)
or die(“Could not connect”);
mysql_select_db(“unicyclep1”)
or die(“Could not select database”);
$sql2 = “SELECT COUNT(*) as `count` FROM image_com WHERE image_id = ‘$id’ ORDER BY `date`”;
$result = mysql_query($sql2) or die(“<br><br><span class=”subHeader”>No Images Uploaded</span>”);
$row = mysql_fetch_array($result);
$numrows = $row[‘count’];
$p = (isset($_GET[“comment”]) and is_numeric($_GET[“comment”]) and ($_GET[“comment”] > 0) and ($_GET[“comment”] <= $numrows))
? $_GET[“comment”]
: $numrows ;
$sql1 = “SELECT * FROM image_com WHERE image_id = ‘$id’ ORDER BY id LIMIT 1 OFFSET “.($p = 1);
$result = mysql_query($sql1) or die(“<br><br><span class=”subHeader”>No Images Uploaded</span>”);
$r = mysql_fetch_assoc($result); ?><?php echo $r[‘date’];
?></td>
</tr>
<tr>
<td width=”128″ height=”89″ align=”center” valign=”top” id=”style5″><p class=”com”><?php echo $r[‘user_name’];
?></p><form action=”viewprofile.php” method=”post”>
<input type=”hidden” name=”username” value=”<?php echo $r[‘user_name’] ?>”>
<input type=”submit” value=”View Profile”></form></td>
<td width=”368″ valign=”top” id=”style10″><p class=”com”><?php echo $r[‘comment’]; ?></p></td>
</tr>
</table><br>
and so on.
I was thinking something like
[code=php]<?php if($p => 1)
{
echo
}; ?>
but i’m not to sure how to put it all together. ?
any ideas?