Jump to content

SO Actually whats wrong?


scheols

Recommended Posts

[quote][code=php:0]

$s1 = mysql_query("SELECT * FROM topics WHERE fid='$s'");

$count = mysql_num_rows($s1);
mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");
[/code][/quote]

welll i have this code and im trying to update the topics on index page so when i add that to one of my pages it doesnt update the forums topics the way it should but when i add it to my add reply page it counts everytime and shows on index then i come back like a hour later and it doesnt update until the next time i count

what should i do
Link to comment
Share on other sites

alright i have a script 2 addtopic's and everytime i add a topic it updates the forum topics so after it updates the mysql_num_rows guess it messes up and doesnt show until another post is made.

[quote]
[code=php:0]
<?php
$s = $_GET['id'];

$name = $logged[username];
$title = htmlspecialchars($_POST['title']);
$post = htmlspecialchars($_POST['post']);
$spost = $_POST['spost'];


if(isset($spost)){

$s1 = mysql_query("SELECT * FROM topics WHERE fid='$s'");

$count = mysql_num_rows($s1);
mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");
mysql_query("INSERT INTO topics(fid,title,post,username) VALUES('$s','$title','$post','$name')") or die(mysql_error());
echo "Post Created Successfully";


}elseif(!isset($spost)){
?>
<table colspan=2 bgColor="#FFFFFF">
<tr>
<td><form  method="post"></td>
</tr>
<tr>
<td>User Name</td>
<td><? echo $logged[username]; ?></td>
</tr>
<tr>
<td>Topic Title</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Post:<td>
<td><textarea width="200" height="200" name="post"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="spost"></td>
<td></form></td>
</tr>
</table>
<? } ?>
[/code]
[/quote]

and i do this on index where i grab the info

[quote]
[code=php:0]
<?php
$nc9 = mysql_query("SELECT * FROM topics") or die(mysql_error());
$f2 = mysql_fetch_array($nc9);


$nc2 = mysql_query("SELECT * FROM forums") or die(mysql_error());
while($f = mysql_fetch_array($nc2)){
if($f[cid] ==$c[id]){
$replies = $f[replies];
$topics = $f[topics];
?>
<table colspan=4 bgColor="#E4EAF2" width="90%" style=" border:1px solid #000;border-top:0px solid #000">
<tr>
<td width="50%"><a href="viewforum.php?fid=<? echo $f[id]; ?>"><? echo $f[title]; ?></a></td>
<td width="20%"><? echo $f[lastpost]; ?></td>
<td width="10%"><? echo $topics; ?></td>
<td width="10%"><? echo $replies; ?></td>
</tr>
</table>
<? }}} ?>
[/code]
[/quote]

so im wondering why does the topics row in forums table doesnt stay updated?
Link to comment
Share on other sites

I believe the problem is at
[code]mysql_query("UPDATE forums SET topics='$count' WHERE id='$s' ");[/code]

Is your topics refer to the latest thread ?

Try this
[code]mysql_query("UPDATE forums SET topics='".$count+1."' WHERE id='$count' ");[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.