scheols Posted August 1, 2006 Share Posted August 1, 2006 [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 countwhat should i do Link to comment https://forums.phpfreaks.com/topic/16171-so-actually-whats-wrong/ Share on other sites More sharing options...
hackerkts Posted August 1, 2006 Share Posted August 1, 2006 Don't mind explain more in details ? Link to comment https://forums.phpfreaks.com/topic/16171-so-actually-whats-wrong/#findComment-66860 Share on other sites More sharing options...
scheols Posted August 1, 2006 Author Share Posted August 1, 2006 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 https://forums.phpfreaks.com/topic/16171-so-actually-whats-wrong/#findComment-66867 Share on other sites More sharing options...
hackerkts Posted August 1, 2006 Share Posted August 1, 2006 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 https://forums.phpfreaks.com/topic/16171-so-actually-whats-wrong/#findComment-66900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.