Help with some PHP code...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fuente
Forum Newbie
Posts: 3
Joined: Fri Nov 14, 2003 9:39 am

Help with some PHP code...

Post by Fuente »

Hey all,

I'm using this PHP code to post comments on my site.

But now I want to set a max number of comments allowed to 75 and once 75 comments have been posted, I want the text input forms to be removed/hidden, so that only the comments themselves are shown.

In the PHP code, $i represents each comment, so I figure an if/else command could be used where if $i equals 75, the code between the two sets of ****** below is removed/hidden.

Code: Select all

<html>
<head>
<title>YourWebsite.com - Comments</title>
<link rel="stylesheet" href="comments.css" type="text/css">
<style type="text/css">
<!--
  a &#123;font-weight:bold; text-decoration:none&#125;
  .comment &#123;font-family:<? echo $font_face; ?>; font-size:<? echo $font_size; ?>&#125;
  .date &#123;color:<? echo $font_altcolor; ?>; font-family:<? echo $font_face; ?>; font-size:<? echo $font_size; ?>; font-weight:bold&#125;
  .form &#123;color:<? echo $form_text; ?>; font-family:<? echo $font_face; ?>; font-size:<?echo $font_size; ?>&#125;
  .input &#123;width:100%&#125;
//-->
</style>

<base target="_blank">
</head>

<body alink="<? echo $body_alink; ?>" bgcolor="<? echo $body_bgcolor; ?>" leftmargin="0" link="<? echo $body_link; ?>" marginheight="0" marginwidth="0" text="<? echo $body_text; ?>" topmargin="0" vlink="<? echo $body_vlink; ?>">
<form method="post" name="frmPost" target="_top">
<center>
<table cellpadding="10" cellspacing="1" width="364" style="border-color:#673922;border-width:2px;border-style:solid;">
<? for($i = $countStart; $i != $countEnd; $i += $countInc) &#123; ?>
<tr>
  <td bgcolor="<? echo $table_bgcolor&#1111;$i % 2]; ?>" class="comment">
  <? echo $comment&#1111;$i]; ?>
  </td>
</tr>
<? &#125; ?>
******
<tr>
  <td bgcolor="<? echo $form_bgcolor; ?>">
  <table border="0" cellpadding="4" cellspacing="0" width="100%">
  <tr>
    <td align="left" class="form" colspan="2" valign="middle" width="100%"><b>Add your comment:</b> (Auto-line breaks enabled.)</td>
  </tr>
  <tr>
    <td align="left" class="form" valign="middle" width="1%">Name:</td>
    <td align="left" valign="middle" width="99%"><input class="input" maxlength="50" name="commentName" size="40" type="text" value="<? echo $commentName; ?>"></td>
  </tr>
  <tr>
    <td align="left" class="form" valign="middle">E-mail:</td>
    <td align="left" valign="middle"><input class="input" maxlength="75" name="commentMail" size="40" type="text" value="<? echo $commentMail; ?>"></td>
  </tr>
  <tr>
    <td align="left" class="form" valign="middle">Web&nbsp;Site:</td>
    <td align="left" valign="middle"><input class="input" maxlength="100" name="commentSite" size="40" type="text" value="<? echo $commentSite; ?>"></td>
  </tr>
  <tr>
    <td align="left" class="form" valign="top">Comment:</td>
    <td align="left" valign="top"><textarea class="input" cols="38" name="commentText" rows="5" wrap="virtual"></textarea></td>
  </tr>
  <tr>
    <td><br></td>
    <td><input class="comment" name="Submit" type="submit" value="Submit">&nbsp;<input class="comment" name="Cancel" onclick="void(window.close())" type="button" value="Cancel"></td>
  </tr>
******
  </table>
  </td>
</tr>
</form>
</table>
</center>
</body>
</html>
Can anyone help me/tell me how this can be done?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

try this

you'll see what i have done

Code: Select all

<html> 
<head> 
<title>YourWebsite.com - Comments</title> 
<link rel="stylesheet" href="comments.css" type="text/css"> 
<style type="text/css"> 
<!-- 
  a {font-weight:bold; text-decoration:none} 
  .comment {font-family:<? echo $font_face; ?>; font-size:<? echo $font_size; ?>} 
  .date {color:<? echo $font_altcolor; ?>; font-family:<? echo $font_face; ?>; font-size:<? echo $font_size; ?>; font-weight:bold} 
  .form {color:<? echo $form_text; ?>; font-family:<? echo $font_face; ?>; font-size:<?echo $font_size; ?>} 
  .input {width:100%} 
//--> 
</style> 

<base target="_blank"> 
</head> 

<body alink="<? echo $body_alink; ?>" bgcolor="<? echo $body_bgcolor; ?>" leftmargin="0" link="<? echo $body_link; ?>" marginheight="0" marginwidth="0" text="<? echo $body_text; ?>" topmargin="0" vlink="<? echo $body_vlink; ?>"> 
<form method="post" name="frmPost" target="_top"> 
<center> 
<table cellpadding="10" cellspacing="1" width="364" style="border-color:#673922;border-width:2px;border-style:solid;"> 
<? for($i = $countStart; $i != $countEnd; $i += $countInc) { ?> 
<tr> 
  <td bgcolor="<? echo $table_bgcolor[$i % 2]; ?>" class="comment"> 
  <? echo $comment[$i]; ?> 
  </td> 
</tr> 
<? } ?> 

<? if($i < 75) { ?>
<tr> 
  <td bgcolor="<? echo $form_bgcolor; ?>"> 
  <table border="0" cellpadding="4" cellspacing="0" width="100%"> 
  <tr> 
    <td align="left" class="form" colspan="2" valign="middle" width="100%"><b>Add your comment:</b> (Auto-line breaks enabled.)</td> 
  </tr> 
  <tr> 
    <td align="left" class="form" valign="middle" width="1%">Name:</td> 
    <td align="left" valign="middle" width="99%"><input class="input" maxlength="50" name="commentName" size="40" type="text" value="<? echo $commentName; ?>"></td> 
  </tr> 
  <tr> 
    <td align="left" class="form" valign="middle">E-mail:</td> 
    <td align="left" valign="middle"><input class="input" maxlength="75" name="commentMail" size="40" type="text" value="<? echo $commentMail; ?>"></td> 
  </tr> 
  <tr> 
    <td align="left" class="form" valign="middle">Web Site:</td> 
    <td align="left" valign="middle"><input class="input" maxlength="100" name="commentSite" size="40" type="text" value="<? echo $commentSite; ?>"></td> 
  </tr> 
  <tr> 
    <td align="left" class="form" valign="top">Comment:</td> 
    <td align="left" valign="top"><textarea class="input" cols="38" name="commentText" rows="5" wrap="virtual"></textarea></td> 
  </tr> 
  <tr> 
    <td><br></td> 
    <td><input class="comment" name="Submit" type="submit" value="Submit"> <input class="comment" name="Cancel" onclick="void(window.close())" type="button" value="Cancel"></td> 
  </tr> 
<? } ?>
  </table> 
  </td> 
</tr> 
</form> 
</table> 
</center> 
</body> 
</html>
Mark
Fuente
Forum Newbie
Posts: 3
Joined: Fri Nov 14, 2003 9:39 am

Post by Fuente »

Thanks Bech! Works perfectly. :)
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

Bech your such a PIMP bro!!!! ;)

Good thing too because I am getting ready to start a nasty project will will probably need hella help with the SQL stuff.


Jason
Post Reply