This is what I have, but i know it's not right: if(" . $row['reply_name'] . " !== '') { echo "display something"; } else { echo "nothing to display"; PHP: I think/hope this will be really simple. Help please? Thanks, ~alhen
$q="select * from table"; $r=mysql_query($q); while ($row = mysql_fetch_array($r)){ $id=$row['id']; if($id != 1) { echo "I am NOT the #1"; } else { echo "I can only be the #1"; } } PHP:
Didn't help... maybe I should post the entire bit of code WITH what you told me to try. <? MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable"); @mysql_select_db( "$database") or die( "Unable to select database"); $query="SELECT * FROM $usertable LEFT JOIN blog_reply ON blog.id = blog_reply.reply_id ORDER BY date DESC"; $result=mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 0) { echo "<div class=\"text\" align=\"center\"><font color=\"7A7838\"><b>No BLOG entries available</b></font></div>"; } else { while ($row = mysql_fetch_array($result)) { $reply_name = $row['reply_name']; echo "<div class=\"text\" align=\"left\"><i>" . $row['day'] . "</b> - " . $row['disp_date'] . "</i><br><b>" . $row['title'] . "</b><br><br>" . $row['comments'] . "<br> <input name=\"id\" type=\"hidden\" value=\"" . $row['id'] . "\"> <input name=\"reply\" value=\"reply to post\" style=\"background-color:#493C36\" type=\"submit\" class=\"form\"><br>"; if($reply_name != '') { echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#333333\"> <tr> <td colspan=\"2\">Comments: </td> </tr> <tr> <td width=\"3%\"> </td> <td width=\"97%\" class=\"smalltext\"><b>" . $row['reply_name'] . "</b> - " . $row['disp_date'] . "<br>" . $row['reply_comments'] . "</td> </tr> </table> <br><center><img src=\"images/break.jpg\"></center><br></div>"; } else { echo "No Comments"; } } ?> PHP: when tried I get this error on the page: Parse error: parse error, unexpected $ in /home/tarag/public_html/blog_page.php on line 83 which is referring to the "$" in the line: if($reply_name != '') { PHP:
always indent your code, easier to read where there is a missing bracket (while statement had one missing) <? MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable"); @mysql_select_db( "$database") or die( "Unable to select database"); $query="SELECT * FROM $usertable LEFT JOIN blog_reply ON blog.id = blog_reply.reply_id ORDER BY date DESC"; $result=mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 0) { echo "<div class=\"text\" align=\"center\"><font color=\"7A7838\"><b>No BLOG entries available</b></font></div>"; } else { while ($row = mysql_fetch_array($result)) { $reply_name = $row['reply_name']; echo "<div class=\"text\" align=\"left\"><i>" . $row['day'] . "</b> - " . $row['disp_date'] . "</i><br><b>" . $row['title'] . "</b><br><br>" . $row['comments'] . "<br> <input name=\"id\" type=\"hidden\" value=\"" . $row['id'] . "\"> <input name=\"reply\" value=\"reply to post\" style=\"background-color:#493C36\" type=\"submit\" class=\"form\"><br>"; if($reply_name != '') { echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#333333\"> <tr> <td colspan=\"2\">Comments: </td> </tr> <tr> <td width=\"3%\"> </td> <td width=\"97%\" class=\"smalltext\"><b>" . $row['reply_name'] . "</b> - " . $row['disp_date'] . "<br>" . $row['reply_comments'] . "</td> </tr> </table> <br><center><img src=\"images/break.jpg\"></center><br></div>"; } else { echo "No Comments"; } } } ?> PHP: or you could just add it to the SQL query so it doesnt print out any data for that record and reply_name != '' Code (markup):
Thank you so much, that did what I was asking for... but I didn't realize the results. I'm trying to create a blog type of function that allows me to post info, then allows comments to each blog. So it'll have multiple comments. As it stands now the comments are showing up, but it creates a new instance of the original post each time. Here's a link to what I mean: http://www.taragraham.com/blog_page.php I'd like it to show the original post one time, then have whatever comments there are underneath it. Any help/direction? Here's my code now: <? MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable"); @mysql_select_db( "$database") or die( "Unable to select database"); $query="SELECT * FROM blog LEFT JOIN blog_reply ON blog.id = blog_reply.reply_id ORDER BY date DESC"; $result=mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 0) { echo "<div class=\"text\" align=\"center\"><font color=\"7A7838\"><b>No BLOG entries available</b></font></div>"; } else { while ($row = mysql_fetch_array($result)) { $reply_name = $row['reply_name']; echo "<div class=\"text\" align=\"left\"><i>" . $row['day'] . "</b> - " . $row['disp_date'] . "</i><br><b>" . $row['title'] . "</b><br><br>" . $row['comments'] . "<br> <input name=\"id\" type=\"hidden\" value=\"" . $row['id'] . "\"> <input name=\"reply\" value=\"reply to post\" style=\"background-color:#493C36\" type=\"submit\" class=\"form\"><br>"; if($reply_name != '') { echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#333333\"> <tr> <td colspan=\"2\">Comments: </td> </tr> <tr> <td width=\"3%\"> </td> <td width=\"97%\" class=\"smalltext\"><b>" . $row['reply_name'] . "</b> - " . $row['reply_date'] . "<br>" . $row['reply_comments'] . "</td> </tr> </table> <br><center><img src=\"images/break.jpg\"></center><br></div>"; } else { echo "No Comments"; } } } ?> PHP:
If you are doing the format BLOG POST BLOG COMMENT BLOG COMMENT BLOG COMMENT BLOG COMMENT BLOG COMMENT BLOG COMMENT You will need to do a single query with a limit of 0,1 to pull the blog post only. Then, have a second query which takes the ID from the single query of the blog post, feeds it into query like $query="SELECT * FROM blog_reply reply_id = '".$blogid.'" ORDER BY date DESC"; //do the while loop here and loop through comments ONLY. PHP:
What I'm looking for is more like this: BLOG POST BLOG COMMENT BLOG COMMENT ------------------------- BLOG POST BLOG COMMENT ------------------------- BLOG POST BLOG COMMENT BLOG COMMENT etc... would I want to put a limit of 0,1 on the blog post if I'm expecting to post multiple blog entries (with multiple comments)?
if your pulling more than 1 blog record (why you would show multi comments and multi blog posts on the same page, I am not sure) then you would need 2 SQL queries (no limit on the 1st, unless you are paginating the page) then inside, have the second while loop, looking up the blogid and loop the comments.