Posted on Friday 21st March 2008 at 11:16 PM | |
zackcez Newbie |
I'm trying to make it count the comments that are stored in the comments table heres my current code: Code <?php mysql_connect("db174.perfora.net", "dbo239605978", "PASSWORDGONE:O") or die(mysql_error()); mysql_select_db("db239605978") or die(mysql_error()); if (isset($_GET['s'])) { $search = $_GET['s']; $query = "SELECT * FROM news WHERE id LIKE '%$search%' ORDER BY id DESC LIMIT 5"; } else { $query = "SELECT * FROM news ORDER BY id DESC LIMIT 5"; } $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<div class=\"box\">"; echo "<a name=\"" . $row['name'] . "\"></a><h1><a href=\"index.html\">" . $row['title1'] . " <span class=\"white\">" . $row['title2'] . "</span></a></h1>"; echo "<p class=\"post-by\">Posted by <a href=\"index.html\">" . $row['auther'] . "</a></p>"; echo "<p>" . $row['story'] . "</p>"; echo "<p class=\"post-footer align-right\">"; echo "<a href=\"index.html\" class=\"readmore\">Read more</a>"; echo "<a href=\"index.html\" class=\"comments\">Comments ($count)</a></p>"; echo "</div>"; } ?> I've tried numerous things to make it then count the number of comments for each story found in the news table...If anyone could please help it, I'd really appreciate it. Thanks, Zack |
Posted on Friday 21st March 2008 at 11:36 PM | |
zackcez Newbie |
ok i got it down to this code: Code <?php mysql_connect("db174.perfora.net", "dbo239605978", "NOPASS?:o") or die(mysql_error()); mysql_select_db("db239605978") or die(mysql_error()); if (isset($_GET['s'])) { $search = $_GET['s']; $query = "SELECT * FROM news WHERE id LIKE '%$search%' ORDER BY id DESC LIMIT 5"; $result2 = mysql_query("SELECT newsid FROM comments WHERE newsid='$row['id']'"); } else { $query = "SELECT * FROM news ORDER BY id DESC LIMIT 5"; } $result = mysql_query($query) or die(mysql_error()); $count = mysql_num_rows($result2); while($row = mysql_fetch_array($result)){ echo "<div class=\"box\">"; echo "<a name=\"" . $row['name'] . "\"></a><h1><a href=\"index.html\">" . $row['title1'] . " <span class=\"white\">" . $row['title2'] . "</span></a></h1>"; echo "<p class=\"post-by\">Posted by <a href=\"index.html\">" . $row['auther'] . "</a></p>"; echo "<p>" . $row['story'] . "</p>"; echo "<p class=\"post-footer align-right\">"; echo "<a href=\"index.html\" class=\"readmore\">Read more</a>"; echo "<a href=\"index.html\" class=\"comments\">Comments ($count)</a></p>"; echo "</div>"; } ?> That should be a bit closer to my problem...but i get an error yet: Code Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/20/d239047801/htdocs/news.php on line 7 I know what the error means I just don't know any other way to use the code... |
Posted on Saturday 22nd March 2008 at 12:33 AM | |
ShadowMage Senior Member |
Code $result2 = mysql_query("SELECT newsid FROM comments WHERE newsid='$row['id']'"); replace with Code $result2 = mysql_query("SELECT newsid FROM comments WHERE newsid='$row[id]'"); |