Search
Left Quote    By failing to prepare, you are preparing to fail.
- Benjamin Franklin    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: "Number of Comments per article_id?"
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 12:29 am on Jun 10 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

No problem, Im just posting this to test that pagination takes effect. I think I set it to 20 replies /per page. This will be the 21st reply. Here goes!

had an error... fixed i think for now. One thing though, I gotta make it when the 21st reply is made, it refreshes to the 2nd page, instead of the first.



Edited at 02:23:39 am on 06/11/05


-bs0d | AllSyntax.com

    Viewed: 6,841 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 5:24 pm on Sep 21 2005    
Unregistered

I'm new here and I'm just wondering if anyone has a tutorial of making articles through the web..



    Viewed: 6,815 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 9:42 pm on Sep 21 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

I will help you out as best I can. What do you mean, a website to display articles you have written? Basically, their are two ways:

static or dynamic.

static would be manually creating each page

dynamic would use server side scripting langauge (like php or asp) and an online database (like mySQL) to store the data in.

Read up on some of the tutorial here, we have tutorials on PHP and MySQL and creating scripts that obtain data stored in a database.

Any other questions, feel free to ask.




-bs0d | AllSyntax.com

    Viewed: 6,811 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 8:45 pm on Sep 22 2005    
Unregistered

Hmm so we have to create another table for just the article and use that code to pick up the id of it and match it with the comment id or something? I'm confused



    Viewed: 6,806 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 12:51 am on Sep 22 2005    
Unregistered

Hmm.. the last code seems to work bs0d, but uh.. how do u add a link to go into that id?



    Viewed: 6,800 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 1:11 am on Sep 22 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

sorry but im kinda lost where you're commin from. You can have a table, say "Articles " in your database that has all tutorials on your site. The table would have a column, ID that uniquely identifies each article.

what you do in the list that displays your tutorials, is display the tutorials as a link with the id from the database, same place and table you got the tutorial name.

then in your view script, you select all pages from the article table where id= $_GET['id']. Id would be passed along in the query string of the URL from the list of tutorials, see?

in your list of tutorials, display the tutorial like:

Code:


<?
echo('<a href=wwww.yours ite.com/article s/view.php?id= '.$query->ar ticle_id.'> '.$query->a rticle_title.' </a>');< br />



are we on the same page, or am i going in the wrong direction?

for comments you select all (comments) from article_comment s table where tutorial_id = $_GET['id'] (tutorial you're viewing)




-bs0d | AllSyntax.com

    Viewed: 6,795 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 1:23 am on Sep 22 2005    
Unregistered


Code:


} else {
echo("thi s article has ".$how_ma ny." comments. <hr>&quo t;
}



Oh I just want to know how u put that into a link to the correct comment page.



    Viewed: 6,792 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 1:30 am on Sep 22 2005    
Unregistered

Hmm another thing, I checked the table after an entry. I didn't see article_id changing at all, it remained 0. Was that suppose to happen?



    Viewed: 6,789 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 3:39 am on Sep 22 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

the article id would be different for each unique id stored as an article in the database. if you have 5 articles , id 1-5 respectively, and you add a commment for article 2, then in the comments table for the comment under article_id should be 2. you select all comments from the comments table in the database where article_id = $_GET['id']




-bs0d | AllSyntax.com

    Viewed: 6,783 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 4:06 am on Sep 23 2005    
Unregistered

bs0d, I was in irc with the nickname Mitsukai attempting to contact you. I tried to do as what you said, but the article_id is not setting to it's proper value. All the entries end up being 0. Therefore, I tried experimenting and it kind of work except that it was showing same numbers in all the articles. Here is the code for the article page:


Code:


$q_articles =mysql_query(& quot;SELECT * FROM `articles`&quo t;
if(!$q_articles ) die(mysql_error ());

while($show = mysql_fetch_obj ect($q_articles )) {

echo("&q uot;.$show-> title." <hr>Poste d by: ".$show-& gt;username.&q uot; @ ".$show-& gt;date." <BR>
".$show-& gt;article.&qu ot;<hr> ";

//now query comments for this article
$q2 = mysql_query(&q uot;SELECT * FROM `comments` WHERE `id` = '".$show ->id." '";
$how_many = mysql_num_rows( $q2);
if($how_many == 0) {
echo('<a href="com ment.php?id='. $show->id.' ">comm ents:(0)</a& gt;<hr>' );
} else {
echo('<a href="com ment.php?id='. $show->id.' ">comm ents: ('.$how_many. ') </a><B R><hr> ');
}//end else
} //end while
?>


(Since article_id was all set to 0 for some weird reason. I tried using id instead cause i saw that only being changed)

I would seriously like to get this to work on my website. I'm not so sure myself (since i'm new to php and mysql) on how I setupped the article mysql table, but it seems to work fine. If you can, can you please like also have a tutorial for article managing w/ comment script attached? Thanks so much...



    Viewed: 6,780 Times | Reply to This | To top
  This user is offline  Mitsukai
  Subject: "re: Number of Comments per article_..." Posted: @ 7:13 am on Sep 23 2005    
Member #: 75
Rank: User - (5)
Since: 09/23/05
Posts: 5

Arg I meant to say is that the article_id still remains 0 when i type in a comment on a 2nd article. So I'm not so sure what's up with that...




    Viewed: 6,774 Times | Reply to This | To top
  This user is online  Guest
  Subject: "re: Number of Comments per article_..." Posted: @ 9:42 am on Sep 23 2005    
Unregistered

Sorry to do multiple posts, but I figured out the problem. Thanks



    Viewed: 6,770 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 12:11 pm on Sep 23 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Ok; sorry I was in bed! I would have continued to help. What did you do to solve the problem?




-bs0d | AllSyntax.com

    Viewed: 6,767 Times | Reply to This | To top
  This user is offline  Mitsukai
  Subject: "re: Number of Comments per article_..." Posted: @ 1:00 am on Sep 23 2005    
Member #: 75
Rank: User - (5)
Since: 09/23/05
Posts: 5

I actually asked someone to help, and he fixed most of the problem. I'm not quite sure what he changed on comment.php, but on the news.php, i've noticed:


Code:


$dbhost='local host';
$dbusername=' ';
$dbuserpass=' ';
$dbname='';

//connecting to mysql
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db ($dbname) or die('Cannot select database.');


$q_articles = mysql_query(&q uot;SELECT * FROM `articles` ORDER BY `id` DESC";
if(!$q_articles ) die(mysql_error ());

while($show = mysql_fetch_obj ect($q_articles )) {

echo("&q uot;.$show-> title." <hr>Poste d by: ".$show-& gt;username.&q uot; @ ".date(' h:i:s a', $show->time) ." on ".$show-& gt;date." <BR>
".$show-& gt;article.&qu ot;<hr>
";

//now query comments for this article
$q2 = mysql_query(&q uot;SELECT * FROM `comments` WHERE `article_id` = '".$show ->id." '"<im g src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;
$howmany = mysql_numrows($ q2);
if($howmany == 0) {
echo('<a href="com ment.php?id='. $show->id.' ">comm ents:(0)</a& gt;<hr>' );
}
if($howmany != 0) {
echo('<a href="com ment.php?id='. $show->id.' ">comm ents: ('.$howmany.' ) </a><B R><hr> ');
}//end else
} //end while



Here is code for the comment page:

Code:

if ($hehe == 1) {
$hehe = 0;
header('Locati on: http://' . $_SERVER['HTTP _HOST'] . $_POST['page' ] . "#comment s";
}
ob_start();
//connect to your database
$dbhost='local host';
$dbusername=' ';
$dbuserpass=' ';
$dbname='';

mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db ($dbname) or die('Cannot select database because of mysql_error()' );

//query comments for this page of this article
$inf = "SELECT * FROM `comments` WHERE page = '".strip slashes($_SERVE R['REQUEST_URI '])."' ORDER BY time ASC";
$info = mysql_query($in f);
if(!$info) die(mysql_error ());

$info_rows = mysql_num_rows( $info);
if($info_rows > 0) {
echo '<h5>Com ments:</h5&g t;';
echo '<table width="95 %">';

while($info2 = mysql_fetch_obj ect($info)) {
echo '<tr>';
echo '<td>&q uot;'.stripsla shes($info2-> ;subject).'&q uot; by: <a href="'. $info2->cont act.'"&g t;'.stripslash es($info2->u sername).'< /a></td&g t; <td><d iv align="ri ght"> @ '.date('h:i:s a', $info2->time ).' on '.$info2->d ate.'</div& gt;</td> ';
echo '</tr>&l t;tr>';
echo '<td colspan=" 2"> '.stripslashes ($info2->com ment).' </td>';
echo '</tr>' ;
}//end while
echo '</table> ;';
echo '<hr width="95 %" noshade>';
} else echo 'No comments for this page. Feel free to be the first <br>';

if(isset($_POST ['submit'])) {
if(!addslashes( $_POST['userna me'])) die('<u> ERROR:</u> ; you must enter a username to add a comment.');
if(!addslashes( $_POST['contac t'])) die('<u> ERROR:</u> ; enter contact method in contact field.');
if(!addslashes( $_POST['subjec t'])) die('<u> ERROR:</u> ; enter a subject to your comment.');
if(!addslashes( $_POST['commen t'])) die('<u> ERROR:</u> ; cannot add comment if you do not enter one!?');


//this is for a valid contact
if(substr($_POS T['contact'], 0,7) != 'mailto:' && !strstr($_POST[ 'contact'],' //')) {
if(strstr($_POS T['contact'], '@'))
$_POST['contac t'] = "mailto: ".$_POST[ 'contact'].&q uot;";
else
$_POST['contac t'] = "http:// ".$_POST[ 'contact'].&q uot;";
} //end valid contact

//try to prevent multiple posts and flooding...
$c = "SELECT * from `comments` WHERE ip = '".$_SER VER['REMOTE_AD DR']."' ";
$c2 = mysql_query($c) ;
while($c3 = mysql_fetch_obj ect($c2)) {
$difference = time() - $c3->time;
if($difference < 300) die('<u> ALERT:</u> ; '.$c3->user name.', You have already commented earlier; if you have a question, try the forums!<BR&g t;');
} //end while

//add comment
$q ="INSERT INTO `comments` (article_id, page, date, time, username, ip, contact, subject, comment) VALUES ('".$HTT P_GET_VARS['id ']."', '".$_POS T['page'].&q uot;', '".$_POS T['date'].&q uot;', '".$_POS T['time'].&q uot;', '".addsl ashes(htmlspeci alchars($_POST[ 'username'])) ."', '".$_SER VER['REMOTE_AD DR']."' , '".addsl ashes(htmlspeci alchars($_POST[ 'contact'])). "', '".addsl ashes(htmlspeci alchars($_POST[ 'subject'])). "', '".addsl ashes(htmlspeci alchars(nl2br($ _POST['comment '])))." ')";

$q2 = mysql_query($q) ;
if(!$q2) die(mysql_error ());

//refresh page so they can see new comment
$haha = 1;
} else { //display form
?>
<form name="com ments" action="& lt;? $_SERVER['PHP_ SELF']; ?>" method="p ost">

<input type="hid den" name="pag e" value="&l t;? echo($_SERVER[ 'REQUEST_URI'] ); ?>"> ;
<input type="hid den" name="dat e" value="&l t;? echo(date(&quo t;F j, Y."); ?>"> ;
<input type="hid den" name="tim e" value="&l t;? echo(time()); ?>"> ;

<table width="90 %" border="0 " cellspacing=&q uot;0" cellpadding=&q uot;0"> ;
<tr>
<td><d iv align="ri ght">U sername: </div>< ;/td>
<td><i nput name="use rname" type="tex t" size="30 " value="& quot;></t d>
</tr>
<tr>
<td><d iv align="ri ght">C ontact: </div>< ;/td>
<td><i nput type="tex t" name="con tact" size="30 " value="& quot;> <i>(email or url)</i>& lt;/td>
</tr>
<td><d iv align="ri ght">S ubject: </div>< ;/td>
<td><i nput type="tex t" name="sub ject" size="30 " value="& quot;></t d>
</tr>
<tr>
<td><d iv align="ri ght">C omment: </div>< ;/td>
<td><t extarea name="com ment" cols="45 " rows="5& quot; wrap="VIR TUAL"> </textarea&g t;</td>
</tr>
<tr>
<td></ td>
<td colspan=" 2">< ;input type="res et" value="Re set Fields"&g t;
<input type="sub mit" name="sub mit" value="Ad d Comment"& gt;</td>
</tr>
</table>
</form>
<?
} // end else
?>





Since the article_id wasn't being recorded correctly =p. But now I'm having issues with refreshing after posting when there is no comment =/. He changed or replace the refreshing code cause when the ppl click on the comment link and post a new comment, it wouldn't refresh.



Edited at 01:20:02 am on 09/24/05


    Viewed: 6,757 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 1:59 am on Sep 23 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

first off, that ob_start(); needs to be the VERY FIRST line in your code, change that and see what happens.

Also, at the beginning it has $hehe, but in the code below, it sets the var "$haha&q uot; - should it be $hehe?




-bs0d | AllSyntax.com

    Viewed: 6,749 Times | Reply to This | To top
  This user is offline  Mitsukai
  Subject: "re: Number of Comments per article_..." Posted: @ 5:56 am on Sep 24 2005    
Member #: 75
Rank: User - (5)
Since: 09/23/05
Posts: 5

Ok I placed the ob_start(); on the very first line after <?, and I changed the $haha to $hehe. Yet I still have the same problem.

Edit: Ok... I tried setting it back to your settings when it comes to refreshing. Still the same problem. It's quite interesting since comment.php itself had no issues with it refreshing. But when you arrive from another site, post a comment, then it doesn't refresh.

The person that I got help from doesn't quite understand the header(); tag so I guess your my last resort. If you can please help!!



Edited at 06:30:56 am on 09/24/05


    Viewed: 6,745 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 4:19 pm on Sep 24 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

hey look what this user posted:

http://www.all syntax.com/foru ms/view.php?f=4 &t=24#115

give that a try? maybe it will solve your problem as well.




-bs0d | AllSyntax.com

    Viewed: 6,736 Times | Reply to This | To top
  This user is offline  Mitsukai
  Subject: "re: Number of Comments per article_..." Posted: @ 9:21 pm on Sep 24 2005    
Member #: 75
Rank: User - (5)
Since: 09/23/05
Posts: 5

 Guest said...

< i>I replaced the include with the code from the comments page directly, and now it works.

I'm not quite getting this correctly... So does he mean he put ob_start(); at news.php? If that's not the case, then what does he mean by replacing the include with the code from the comments page?



Edited at 09:31:35 pm on 09/24/05


    Viewed: 6,732 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Number of Comments per article_..." Posted: @ 9:40 pm on Sep 24 2005    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

I guess what worked for him was to instead of having a comments.php file, and using include('../pa th/to/comemnts. php'); he just pasted all of the code from comments.php in the script that displayed his article and it worked.




-bs0d | AllSyntax.com

    Viewed: 6,728 Times | Reply to This | To top
  This user is offline  Mitsukai
  Subject: "re: Number of Comments per article_..." Posted: @ 8:19 am on Sep 26 2005    
Member #: 75
Rank: User - (5)
Since: 09/23/05
Posts: 5

Hmm well I don't want the actual comment form to be in the article page. I just wanted a link that leads to the comment page for that article. So I don't think pasting all the code in comment.php would make it better or at least it doesn't make sense to me.



Edited at 08:22:07 am on 09/26/05


    Viewed: 6,722 Times | Reply to This | To top
Viewing Page: 2 of 3


« Prev.
1 | 2 | 3 |
Next »





"AllSyntax.com" Copyright © 2002-2019; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank